Fixes #64041
Details
- Reviewers
philnik MitalAshok - Group Reviewers
Restricted Project - Commits
- rGbed75faf7d76: [Clang] Reject programs declaring namespace std to be inline
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
https://eel.is/c++draft/namespace.std#7 is in the library clause.
Couldn't find a better place to put the test other than clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp which is for https://eel.is/c++draft/namespace.def.general#4.sentence-2.
Can you add a test for foo::std ? I suspects it warns, which is incorrect ? Can you add additional tests for inline std::foo ? (which should warn)
Thanks!
This does currently break namespace foo { inline namespace std {} }, namespace foo::inline std {}, etc.
clang/lib/Sema/SemaDeclCXX.cpp | ||
---|---|---|
11396 | You need to check if this is a std namespace declaration at file scope, namespace foo::inline std {} in a namespace scope should be fine. The check for this is a few lines below: CurContext->getRedeclContext()->isTranslationUnit(). | |
11429–11430 | This ends up giving two errors on the same line if this wasn't the first declaration (error: namespace 'std' cannot be declared inline followed by error: non-inline namespace cannot be reopened as inline; note: previous definition is here). The wording for the second error is also a little confusing (it cannot be opened at all as inline, let alone reopened), so consider refactoring so that both diagnostics can't be issued at once |
You need to check if this is a std namespace declaration at file scope, namespace foo::inline std {} in a namespace scope should be fine.
The check for this is a few lines below: CurContext->getRedeclContext()->isTranslationUnit().