token-name-resolution

Reserved names in the global namespace

自古美人都是妖i 提交于 2020-01-02 04:53:09
问题 Arising from my answer to Dynamic array of objects in C++ and as a follow up to What are the rules about using an underscore in a C++ identifier?: apparently, names beginning with _ followed by an uppercase letter are reserved in the global namespace. 17.4.3.2.1 Global names [ lib.global.names ] Certain sets of names and function signatures are always reserved to the implementation: Each name that contains a double underscore ( __ ) or begins with an underscore followed by an uppercase letter

Are there different rules regarding ADL or naming clashes with regard to overloaded operators?

巧了我就是萌 提交于 2019-12-22 09:58:04
问题 I think this example best illustrates my question: namespace N { class C { public: friend bool operator==(const C& c, const C& x) { return true; } friend bool f(const C& c, const C& x) { return true; } }; class D { public: bool operator==(const D& x) { bool a = C{} == C{}; // this works return true; } bool f(const D& x) { bool a = f(C{}, C{}); // this does not work return true; } }; } I have always viewed overloaded operators as being just like function except for the 'calling syntax' if you

The actual result of name resolution in the class template is different from the c++ 03 standard

独自空忆成欢 提交于 2019-12-21 03:34:23
问题 I test the code in the c++ standard ISO/IEC 14882-03 14.6.1/9 on Xcode 4.1 and Visual Studio 2008. The outputs of the two compiler are both different from the expected result of the standard. The code is pasted below. #include <stdio.h> #include <iostream> using namespace std; void f(char); template <class T > void g(T t) { f(1); f(T(1)); f(t); } void f(int); void h() { g(2); g('a'); } void f(int) { cout << "f int" << endl; } void f(char) { cout << "f char" << endl; } int main() { h(); return

Differences of the interpretation of a non-dependent construct between definition context and point of instantiation in c++

跟風遠走 提交于 2019-12-19 07:39:37
问题 N4527 14.6 [temp.res]/p8 If a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, the program is ill-formed; no diagnostic is required. If the interpretation of such a construct in the hypothetical instantiation is different from the interpretation of the corresponding construct in any actual instantiation of the template, the program is ill-formed; no diagnostic is required. [ Note:

Declaration of method changes meaning of symbol

五迷三道 提交于 2019-12-18 04:33:30
问题 For the following code: struct foo {}; struct A { typedef foo foo_type; void foo(); }; GCC gives a compiler error: test.cpp:7:14: error: declaration of 'void A::foo()' [-fpermissive] void foo(); ^ test.cpp:1:8: error: changes meaning of 'foo' from 'struct foo' [-fpermissive] struct foo {}; ^ But clang accepts it without compiler errors. Who is right? Note that if the typedef is removed, or changed to typedef ::foo foo_type , both gcc and clang accept the code. 回答1: gcc is correct, but clang

Are there different rules regarding ADL or naming clashes with regard to overloaded operators?

若如初见. 提交于 2019-12-05 21:27:26
I think this example best illustrates my question: namespace N { class C { public: friend bool operator==(const C& c, const C& x) { return true; } friend bool f(const C& c, const C& x) { return true; } }; class D { public: bool operator==(const D& x) { bool a = C{} == C{}; // this works return true; } bool f(const D& x) { bool a = f(C{}, C{}); // this does not work return true; } }; } I have always viewed overloaded operators as being just like function except for the 'calling syntax' if you will. I just noticed the above difference however in ADL or name lookup rules (I don't know which one).

Reserved names in the global namespace

南楼画角 提交于 2019-12-05 08:27:36
Arising from my answer to Dynamic array of objects in C++ and as a follow up to What are the rules about using an underscore in a C++ identifier? : apparently, names beginning with _ followed by an uppercase letter are reserved in the global namespace. 17.4.3.2.1 Global names [ lib.global.names ] Certain sets of names and function signatures are always reserved to the implementation: Each name that contains a double underscore ( __ ) or begins with an underscore followed by an uppercase letter (2.11) is reserved to the implementation for any use. Each name that begins with an underscore is

The actual result of name resolution in the class template is different from the c++ 03 standard

﹥>﹥吖頭↗ 提交于 2019-12-03 10:44:43
I test the code in the c++ standard ISO/IEC 14882-03 14.6.1/9 on Xcode 4.1 and Visual Studio 2008. The outputs of the two compiler are both different from the expected result of the standard. The code is pasted below. #include <stdio.h> #include <iostream> using namespace std; void f(char); template <class T > void g(T t) { f(1); f(T(1)); f(t); } void f(int); void h() { g(2); g('a'); } void f(int) { cout << "f int" << endl; } void f(char) { cout << "f char" << endl; } int main() { h(); return 0; } As the description of the standard. The expected output should be f char f int f int f char f

Differences of the interpretation of a non-dependent construct between definition context and point of instantiation in c++

谁说我不能喝 提交于 2019-12-01 05:50:39
N4527 14.6 [temp.res]/p8 If a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, the program is ill-formed; no diagnostic is required. If the interpretation of such a construct in the hypothetical instantiation is different from the interpretation of the corresponding construct in any actual instantiation of the template, the program is ill-formed; no diagnostic is required. [ Note: This can happen in situations including the following: (8.1) — a type used in a non-dependent name is

List of C++ name resolution (and overloading) rules

岁酱吖の 提交于 2019-11-26 18:00:54
问题 Where I can find a list of the rules that a C++ compliant compiler must apply in order to perform names resolution (including overloading)? I'd like something like a natural-language algorithm or flow chart. C++ standard of course has this set of rules but it is build up as new language statements are introduced and the result it's pretty hard to remember. To make a long story short, I'd like to know the complete and detailed answer to the question " What compiler do when it see the name 'A'