Skip to content

Commit 528e6eb

Browse files
committed
[clang] Improve diagnostic for reopened inline namespace
Reviewed By: cor3ntin, aaron.ballman Differential Revision: https://reviews.llvm.org/D122278
1 parent fc3cdd0 commit 528e6eb

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ Improvements to Clang's diagnostics
8383
- ``-Wliteral-range`` will warn on floating-point equality comparisons with
8484
constants that are not representable in a casted value. For example,
8585
``(float) f == 0.1`` is always false.
86+
- ``-Winline-namespace-reopened-noninline`` now takes into account that the
87+
``inline`` keyword must appear on the original but not necessarily all
88+
extension definitions of an inline namespace and therefore points its note
89+
at the original definition. This fixes `Issue 50794 (PR51452)
90+
<https://github.com/llvm/llvm-project/issues/50794>`_.
8691

8792
Non-comprehensive list of changes in this release
8893
-------------------------------------------------

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11060,6 +11060,11 @@ static void DiagnoseNamespaceInlineMismatch(Sema &S, SourceLocation KeywordLoc,
1106011060
NamespaceDecl *PrevNS) {
1106111061
assert(*IsInline != PrevNS->isInline());
1106211062

11063+
// 'inline' must appear on the original definition, but not necessarily
11064+
// on all extension definitions, so the note should point to the first
11065+
// definition to avoid confusion.
11066+
PrevNS = PrevNS->getFirstDecl();
11067+
1106311068
if (PrevNS->isInline())
1106411069
// The user probably just forgot the 'inline', so suggest that it
1106511070
// be added back.

clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ inline namespace foo4::foo5::foo6 { // expected-error {{nested namespace definit
1717
// expected-warning@+2 {{inline nested namespace definition is incompatible with C++ standards before C++20}}
1818
#endif
1919
namespace valid1::valid2::inline valid3::inline valid4::valid5 {}
20-
// expected-note@-1 2 {{previous definition is here}}
20+
// expected-note@-1 4 {{previous definition is here}}
2121

2222
#if __cplusplus <= 201402L
2323
// expected-warning@+3 {{nested namespace definition is a C++17 extension; define each namespace separately}}
@@ -34,7 +34,6 @@ namespace valid1::valid2::valid3::valid4::valid5 {}
3434
// expected-warning@+2 {{inline nested namespace definition is incompatible with C++ standards before C++20}}
3535
#endif
3636
namespace valid1::valid2::inline valid3::inline valid4::valid5 {}
37-
// expected-note@-1 2 {{previous definition is here}}
3837

3938
namespace valid1 {
4039
namespace valid2 {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -fsyntax-only -Wall -verify -std=c++11 %s
2+
3+
// Regression test for #50794.
4+
5+
// expected-note@+1 2 {{previous definition is here}}
6+
inline namespace X {}
7+
8+
namespace X {} // expected-warning {{inline namespace reopened as a non-inline namespace}}
9+
namespace X {} // expected-warning {{inline namespace reopened as a non-inline namespace}}

0 commit comments

Comments
 (0)