[llvm-bugs] [Bug 42523] New: Non-inline unnamed namespaces can be redeclared as inline in some cases

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 5 09:54:10 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42523

            Bug ID: 42523
           Summary: Non-inline unnamed namespaces can be redeclared as
                    inline in some cases
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: maltsevm at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The following code is correctly rejected:

inline namespace I {
    namespace N {}
    using namespace N;
    namespace N { int i; }
}
inline namespace N { }

Clang produces the following diagnostic:
<source>:6:18: error: non-inline namespace cannot be reopened as inline
inline namespace N { }
                 ^
<source>:4:15: note: previous definition is here
    namespace N { int i; }
              ^
1 error generated.
Compiler returned: 1

But this code is accepted:

inline namespace I {
    namespace { int i; }
}
inline namespace { }

According to the standard ([namespace.unnamed]/1), An
unnamed-namespace-definition behaves as if it were replaced by

    inline_opt namespace unique { /* empty body */ }
    using namespace unique ;
    namespace unique { namespace-body }

where inline appears if and only if it appears in the
unnamed-namespace-definition and all occurrences of unique in a translation
unit are replaced by the same identifier, and this identifier differs from all
other identifiers in the translation unit.

I.e. the second example should also be rejected.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190705/b9374b3a/attachment.html>


More information about the llvm-bugs mailing list