Non-inline unnamed namespaces can be redeclared as inline in some cases
| Bugzilla Link | 42523 |
| Version | trunk |
| OS | Linux |
| CC | @DougGregor,@K-ballo,@zygoloid |
Extended Description
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.
@llvm/issue-subscribers-clang-frontend
Author: Mikhail Maltsev (miyuki)
Extended Description
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.
I don't think your interpretation is correct, no implementation reject: https://godbolt.org/z/PWqqcYeGK
We have I::unique and unique.