Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
7679 Discussions

(c++11) template non dependent name binding issues

Andrey_K_
Beginner
244 Views

Hi,

According to the C++11 specification (in my case I refer to draft n3376), non dependent name found at template declaration should be bound at point of declaration. Here is quotation from standard:

14.6 Name resolution

..."If a name does not depend on a template-parameter (as defined in 14.6.2), a declaration (or set of declarations) for that name shall be in scope at the point where the name appears in the template definition; the name is bound to the declaration (or declarations) found at that point and this binding is not affected by declarations that are visible at the point of instantiation."

Consider following example:

#include <iostream>
using namespace std;

static void g(double) {
	cout << "double" << endl;
}

template<typename T> void Foo(T t){
	g(0); // not dependent name, expecting it will be resolved at point of declaration
	g(t); // dependent name, expecting it will be resolved at point of instantiation

}

static void g(int) {
	cout << "int" << endl;
}

void TemplateNameResolution() {
	Foo(1.0);
}

With my understanding of standard I expect it will output: double, double

But actually it output: int, double.

Am I wrong?

I'm using Intel® C++ Composer XE 2015.

 

0 Kudos
1 Solution
Judith_W_Intel
Employee
244 Views

 

You must be using our Windows compiler. On Linux the result is as you expected. We emulate the Microsoft compiler on Windows which does not conform to the standard in this regard. The /Qstd=c++11 switch just enables some additional c++11 features it doesn't make the compiler follow the standard in a strict manner. If it did, the iostream header on Windows would not compile correctly...

Judy

 

View solution in original post

2 Replies
Judith_W_Intel
Employee
245 Views

 

You must be using our Windows compiler. On Linux the result is as you expected. We emulate the Microsoft compiler on Windows which does not conform to the standard in this regard. The /Qstd=c++11 switch just enables some additional c++11 features it doesn't make the compiler follow the standard in a strict manner. If it did, the iostream header on Windows would not compile correctly...

Judy

 

Andrey_K_
Beginner
244 Views

Thanks, I will forward this issue to  microsoft

Reply