[PATCH] D126664: Expand definition deprecation warning to include constexpr statements.

2022-06-01 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1f6ea2a37c43: Expand definition deprecation warning to 
include constexpr statements. (authored by luken-google, committed by 
aaron.ballman).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126664/new/

https://reviews.llvm.org/D126664

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/basic/basic.def/p2.cpp


Index: clang/test/CXX/basic/basic.def/p2.cpp
===
--- clang/test/CXX/basic/basic.def/p2.cpp
+++ clang/test/CXX/basic/basic.def/p2.cpp
@@ -5,4 +5,9 @@
 static constexpr int n = 0;
   };
   const int A::n; // expected-warning {{deprecated}}
+
+  struct B {
+static constexpr int m = 0;
+  };
+  constexpr int B::m; // expected-warning {{deprecated}}
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4508,15 +4508,15 @@
   }
 
   // C++ doesn't have tentative definitions, so go right ahead and check here.
-  if (getLangOpts().CPlusPlus &&
-  New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  if (getLangOpts().CPlusPlus) {
 if (Old->isStaticDataMember() && Old->getCanonicalDecl()->isInline() &&
 Old->getCanonicalDecl()->isConstexpr()) {
   // This definition won't be a definition any more once it's been merged.
   Diag(New->getLocation(),
diag::warn_deprecated_redundant_constexpr_static_def);
-} else if (VarDecl *Def = Old->getDefinition()) {
-  if (checkVarDeclRedefinition(Def, New))
+} else if (New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  VarDecl *Def = Old->getDefinition();
+  if (Def && checkVarDeclRedefinition(Def, New))
 return;
 }
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -241,6 +241,9 @@
   suggest ``#else`` as an alternative. ``#elifdef`` and ``#elifndef`` are only
   suggested when in C2x or C++2b mode. Fixes
   `Issue 51598 `_.
+- The ``-Wdeprecated`` diagnostic will now warn on out-of-line ``constexpr``
+  declarations downgraded to definitions in C++1z, in addition to the
+  existing warning on out-of-line ``const`` declarations.
 
 Non-comprehensive list of changes in this release
 -


Index: clang/test/CXX/basic/basic.def/p2.cpp
===
--- clang/test/CXX/basic/basic.def/p2.cpp
+++ clang/test/CXX/basic/basic.def/p2.cpp
@@ -5,4 +5,9 @@
 static constexpr int n = 0;
   };
   const int A::n; // expected-warning {{deprecated}}
+
+  struct B {
+static constexpr int m = 0;
+  };
+  constexpr int B::m; // expected-warning {{deprecated}}
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4508,15 +4508,15 @@
   }
 
   // C++ doesn't have tentative definitions, so go right ahead and check here.
-  if (getLangOpts().CPlusPlus &&
-  New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  if (getLangOpts().CPlusPlus) {
 if (Old->isStaticDataMember() && Old->getCanonicalDecl()->isInline() &&
 Old->getCanonicalDecl()->isConstexpr()) {
   // This definition won't be a definition any more once it's been merged.
   Diag(New->getLocation(),
diag::warn_deprecated_redundant_constexpr_static_def);
-} else if (VarDecl *Def = Old->getDefinition()) {
-  if (checkVarDeclRedefinition(Def, New))
+} else if (New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  VarDecl *Def = Old->getDefinition();
+  if (Def && checkVarDeclRedefinition(Def, New))
 return;
 }
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -241,6 +241,9 @@
   suggest ``#else`` as an alternative. ``#elifdef`` and ``#elifndef`` are only
   suggested when in C2x or C++2b mode. Fixes
   `Issue 51598 `_.
+- The ``-Wdeprecated`` diagnostic will now warn on out-of-line ``constexpr``
+  declarations downgraded to definitions in C++1z, in addition to the
+  existing warning on out-of-line ``const`` declarations.
 
 Non-comprehensive list of changes in this release
 -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126664: Expand definition deprecation warning to include constexpr statements.

2022-06-01 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google updated this revision to Diff 433404.
luken-google added a comment.

Squash commit to include original changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126664/new/

https://reviews.llvm.org/D126664

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/basic/basic.def/p2.cpp


Index: clang/test/CXX/basic/basic.def/p2.cpp
===
--- clang/test/CXX/basic/basic.def/p2.cpp
+++ clang/test/CXX/basic/basic.def/p2.cpp
@@ -5,4 +5,9 @@
 static constexpr int n = 0;
   };
   const int A::n; // expected-warning {{deprecated}}
+
+  struct B {
+static constexpr int m = 0;
+  };
+  constexpr int B::m; // expected-warning {{deprecated}}
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4508,15 +4508,15 @@
   }
 
   // C++ doesn't have tentative definitions, so go right ahead and check here.
-  if (getLangOpts().CPlusPlus &&
-  New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  if (getLangOpts().CPlusPlus) {
 if (Old->isStaticDataMember() && Old->getCanonicalDecl()->isInline() &&
 Old->getCanonicalDecl()->isConstexpr()) {
   // This definition won't be a definition any more once it's been merged.
   Diag(New->getLocation(),
diag::warn_deprecated_redundant_constexpr_static_def);
-} else if (VarDecl *Def = Old->getDefinition()) {
-  if (checkVarDeclRedefinition(Def, New))
+} else if (New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  VarDecl *Def = Old->getDefinition();
+  if (Def && checkVarDeclRedefinition(Def, New))
 return;
 }
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -241,6 +241,9 @@
   suggest ``#else`` as an alternative. ``#elifdef`` and ``#elifndef`` are only
   suggested when in C2x or C++2b mode. Fixes
   `Issue 51598 `_.
+- The ``-Wdeprecated`` diagnostic will now warn on out-of-line ``constexpr``
+  declarations downgraded to definitions in C++1z, in addition to the
+  existing warning on out-of-line ``const`` declarations.
 
 Non-comprehensive list of changes in this release
 -


Index: clang/test/CXX/basic/basic.def/p2.cpp
===
--- clang/test/CXX/basic/basic.def/p2.cpp
+++ clang/test/CXX/basic/basic.def/p2.cpp
@@ -5,4 +5,9 @@
 static constexpr int n = 0;
   };
   const int A::n; // expected-warning {{deprecated}}
+
+  struct B {
+static constexpr int m = 0;
+  };
+  constexpr int B::m; // expected-warning {{deprecated}}
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4508,15 +4508,15 @@
   }
 
   // C++ doesn't have tentative definitions, so go right ahead and check here.
-  if (getLangOpts().CPlusPlus &&
-  New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  if (getLangOpts().CPlusPlus) {
 if (Old->isStaticDataMember() && Old->getCanonicalDecl()->isInline() &&
 Old->getCanonicalDecl()->isConstexpr()) {
   // This definition won't be a definition any more once it's been merged.
   Diag(New->getLocation(),
diag::warn_deprecated_redundant_constexpr_static_def);
-} else if (VarDecl *Def = Old->getDefinition()) {
-  if (checkVarDeclRedefinition(Def, New))
+} else if (New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  VarDecl *Def = Old->getDefinition();
+  if (Def && checkVarDeclRedefinition(Def, New))
 return;
 }
   }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -241,6 +241,9 @@
   suggest ``#else`` as an alternative. ``#elifdef`` and ``#elifndef`` are only
   suggested when in C2x or C++2b mode. Fixes
   `Issue 51598 `_.
+- The ``-Wdeprecated`` diagnostic will now warn on out-of-line ``constexpr``
+  declarations downgraded to definitions in C++1z, in addition to the
+  existing warning on out-of-line ``const`` declarations.
 
 Non-comprehensive list of changes in this release
 -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126664: Expand definition deprecation warning to include constexpr statements.

2022-06-01 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google added a comment.

Thanks for the review! I do need someone to commit on my behalf. Please commit 
with name "Luke Nihlen" and email address "lu...@google.com".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126664/new/

https://reviews.llvm.org/D126664

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126664: Expand definition deprecation warning to include constexpr statements.

2022-06-01 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google updated this revision to Diff 433395.
luken-google added a comment.

Add release note.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126664/new/

https://reviews.llvm.org/D126664

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -241,6 +241,9 @@
   suggest ``#else`` as an alternative. ``#elifdef`` and ``#elifndef`` are only
   suggested when in C2x or C++2b mode. Fixes
   `Issue 51598 `_.
+- The ``-Wdeprecated`` diagnostic will now warn on out-of-line ``constexpr``
+  declarations downgraded to definitions in C++1z, in addition to the
+  existing warning on out-of-line ``const`` declarations.
 
 Non-comprehensive list of changes in this release
 -


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -241,6 +241,9 @@
   suggest ``#else`` as an alternative. ``#elifdef`` and ``#elifndef`` are only
   suggested when in C2x or C++2b mode. Fixes
   `Issue 51598 `_.
+- The ``-Wdeprecated`` diagnostic will now warn on out-of-line ``constexpr``
+  declarations downgraded to definitions in C++1z, in addition to the
+  existing warning on out-of-line ``const`` declarations.
 
 Non-comprehensive list of changes in this release
 -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126664: Expand definition deprecation warning to include constexpr statements.

2022-05-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, but please add a release note about the new diagnostic behavior.

Do you need someone to commit on your behalf? If so, what name and email 
address would you like used for patch attribution?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126664/new/

https://reviews.llvm.org/D126664

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126664: Expand definition deprecation warning to include constexpr statements.

2022-05-31 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a reviewer: aaron.ballman.
hans added a comment.

Looks reasonable to me. It would be good if Richard or Aaron could take a look 
too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126664/new/

https://reviews.llvm.org/D126664

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126664: Expand definition deprecation warning to include constexpr statements.

2022-05-30 Thread Luke Nihlen via Phabricator via cfe-commits
luken-google created this revision.
Herald added a project: All.
luken-google requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang currently warns on definitions downgraded to declarations
with a const modifier, but not for a constexpr modifier. This patch
updates the warning logic to warn on both inputs, and adds a test to
check the additional case as well.

See also: https://bugs.chromium.org/p/chromium/issues/detail?id=1284718


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126664

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/basic/basic.def/p2.cpp


Index: clang/test/CXX/basic/basic.def/p2.cpp
===
--- clang/test/CXX/basic/basic.def/p2.cpp
+++ clang/test/CXX/basic/basic.def/p2.cpp
@@ -5,4 +5,9 @@
 static constexpr int n = 0;
   };
   const int A::n; // expected-warning {{deprecated}}
+
+  struct B {
+static constexpr int m = 0;
+  };
+  constexpr int B::m; // expected-warning {{deprecated}}
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4508,15 +4508,15 @@
   }
 
   // C++ doesn't have tentative definitions, so go right ahead and check here.
-  if (getLangOpts().CPlusPlus &&
-  New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  if (getLangOpts().CPlusPlus) {
 if (Old->isStaticDataMember() && Old->getCanonicalDecl()->isInline() &&
 Old->getCanonicalDecl()->isConstexpr()) {
   // This definition won't be a definition any more once it's been merged.
   Diag(New->getLocation(),
diag::warn_deprecated_redundant_constexpr_static_def);
-} else if (VarDecl *Def = Old->getDefinition()) {
-  if (checkVarDeclRedefinition(Def, New))
+} else if (New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  VarDecl *Def = Old->getDefinition();
+  if (Def && checkVarDeclRedefinition(Def, New))
 return;
 }
   }


Index: clang/test/CXX/basic/basic.def/p2.cpp
===
--- clang/test/CXX/basic/basic.def/p2.cpp
+++ clang/test/CXX/basic/basic.def/p2.cpp
@@ -5,4 +5,9 @@
 static constexpr int n = 0;
   };
   const int A::n; // expected-warning {{deprecated}}
+
+  struct B {
+static constexpr int m = 0;
+  };
+  constexpr int B::m; // expected-warning {{deprecated}}
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4508,15 +4508,15 @@
   }
 
   // C++ doesn't have tentative definitions, so go right ahead and check here.
-  if (getLangOpts().CPlusPlus &&
-  New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  if (getLangOpts().CPlusPlus) {
 if (Old->isStaticDataMember() && Old->getCanonicalDecl()->isInline() &&
 Old->getCanonicalDecl()->isConstexpr()) {
   // This definition won't be a definition any more once it's been merged.
   Diag(New->getLocation(),
diag::warn_deprecated_redundant_constexpr_static_def);
-} else if (VarDecl *Def = Old->getDefinition()) {
-  if (checkVarDeclRedefinition(Def, New))
+} else if (New->isThisDeclarationADefinition() == VarDecl::Definition) {
+  VarDecl *Def = Old->getDefinition();
+  if (Def && checkVarDeclRedefinition(Def, New))
 return;
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits