In the C++ standard, section 9.3 paragraph 2:

  "A member function definition that appears outside of the class definition
   shall appear in a namespace scope enclosing the class definition."

This is similar to 7.3.1.2p2 except for class members.

Therefore, the following code should be rejected:

  namespace NS1 {
    struct S {
      int foo();
    };
  }

  namespace NS2 {
    int NS1::S::foo() { return 0; }
  }

but g++-3.4.3 does not reject it, and issues no warnings with -Wall.

Intel C++ 8.1 properly rejects it.

-- 
           Summary: accept-invalid definition not in enclosing namespace
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: smcpeak at cs dot berkeley dot edu
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20711

Reply via email to