c++ - Compile error when defining a member function, but only in GCC -


the following program compiles without errors msvs, clang , gcc:

class a;  namespace y {     using ::a;     class {}; }  int main() {} 

now let's define member function. still compiles msvs , clang, not gcc:

class a;  namespace y {     using ::a;     class { void f() {} }; }  int main() {} 

gcc gives following error message:

  • prog.cc:5:22: error: definition of 'void a::f()' not in namespace enclosing 'a' [-fpermissive]

why that? bug in gcc?

if second version of program violates rule of c++ standard, rule violate , why doesn't msvs , clang give diagnostic message violation?

is case of ambiguity of c++ standard?

from error message looks gcc incorrectly thinks have violation of following rule:

we not have violation of rule since member function definition inside class definition. theory gcc confuses declaration class a; in global namespace class definition class { ... } in namespace y. think have bug in gcc.

with gcc declare same entity. can seen observing in first version of program possible use ::a complete type in main when compiling gcc. same msvs. clang declare different entities. difference may because of ambiguity in c++ standard. regardless of such ambiguity not violating http://eel.is/c++draft/class.mfct#2 . rule clear.

related question: class declaration in same scope using declaration compiles in gcc not msvs

both of these programs ill-formed according c++ standard. because of same reason in related question:

class declaration in same scope using declaration compiles in gcc not msvs

all compilers should give compile error in both cases: indicates bug in msvs, clang , gcc.

the bug in clang has been confirmed , fixed: https://llvm.org/bugs/show_bug.cgi?id=24030

the reason gcc gives strange error message second program gets confused when failed detect error present in both first , second program.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -