diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7f58aea5f83ad..72df10a194fb5 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -134,6 +134,8 @@ Resolutions to C++ Defect Reports - Bumped the ``__cpp_constexpr`` feature-test macro to ``202002L`` in C++20 mode as indicated in `P2493R0 `_. +- Implemented `CWG3005 Function parameters should never be name-independent `_. + C Language Changes ------------------ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 67ff3f055ca5a..63937ddc3e386 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -7542,16 +7542,20 @@ NamedDecl *Sema::ActOnVariableDeclarator( DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec(); StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec()); - if (LangOpts.CPlusPlus && (DC->isClosure() || DC->isFunctionOrMethod()) && SC != SC_Static && SC != SC_Extern && II && II->isPlaceholder()) { + IsPlaceholderVariable = true; + if (!Previous.empty()) { NamedDecl *PrevDecl = *Previous.begin(); bool SameDC = PrevDecl->getDeclContext()->getRedeclContext()->Equals( DC->getRedeclContext()); - if (SameDC && isDeclInScope(PrevDecl, CurContext, S, false)) - DiagPlaceholderVariableDefinition(D.getIdentifierLoc()); + if (SameDC && isDeclInScope(PrevDecl, CurContext, S, false)) { + IsPlaceholderVariable = !isa(PrevDecl); + if (IsPlaceholderVariable) + DiagPlaceholderVariableDefinition(D.getIdentifierLoc()); + } } } diff --git a/clang/test/CXX/drs/cwg30xx.cpp b/clang/test/CXX/drs/cwg30xx.cpp new file mode 100644 index 0000000000000..a0e13013b1bbf --- /dev/null +++ b/clang/test/CXX/drs/cwg30xx.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected %s +// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected %s +// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected %s +// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected %s +// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected %s +// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected %s +// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected %s + + +namespace cwg3005 { // cwg3005: 21 open 2025-03-10 + +void f( + int _, // #cwg3005-first-param + int _) + // expected-error@-1 {{redefinition of parameter '_'}} + // expected-note@#cwg3005-first-param {{previous definition is here}} +{ + int _; + // expected-error@-1 {{redefinition of '_'}} + // expected-note@#cwg3005-first-param {{previous declaration is here}} +} + +} // namespace cwg3005 diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html index 421c189cfe1f4..52c9cb7d37c23 100755 --- a/clang/www/cxx_dr_status.html +++ b/clang/www/cxx_dr_status.html @@ -17890,7 +17890,11 @@

C++ defect report implementation status

3005 open Function parameters should never be name-independent - Not resolved + +
+ Not resolved + Clang 21 implements 2025-03-10 resolution +
3006