[PATCH] D145841: [clang][Interp] Fix diagnostics for calling non-constexpr constructors

2023-04-03 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58cf70b2cdc1: [clang][Interp] Fix diagnostics for calling 
non-constexpr constructors (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D145841?vs=504406=510485#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145841

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -308,7 +308,7 @@
 };
 
 namespace DeriveFailures {
-  struct Base { // ref-note 2{{declared here}}
+  struct Base { // ref-note 2{{declared here}} expected-note {{declared here}}
 int Val;
   };
 
@@ -316,13 +316,15 @@
 int OtherVal;
 
 constexpr Derived(int i) : OtherVal(i) {} // ref-error {{never produces a 
constant expression}} \
-  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
+  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}} \
+  // expected-note {{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
   };
 
   constexpr Derived D(12); // ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{in call to 'Derived(12)'}} \
// ref-note {{declared here}} \
-   // expected-error {{must be initialized by a 
constant expression}}
+   // expected-error {{must be initialized by a 
constant expression}} \
+   // expected-note {{in call to 'Derived(12)'}}
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant 
expression}} \
  // ref-note {{initializer of 'D' is not a 
constant expression}} \
  // expected-error {{not an integral constant 
expression}} \
@@ -348,7 +350,8 @@
   };
 
   struct YetAnotherDerived : YetAnotherBase {
-using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}}
+using YetAnotherBase::YetAnotherBase; // ref-note {{declared here}} \
+  // expected-note {{declared here}}
 int OtherVal;
 
 constexpr bool doit() const { return Val == OtherVal; }
@@ -356,8 +359,8 @@
 
   constexpr YetAnotherDerived Oops(0); // ref-error {{must be initialized by a 
constant expression}} \
// ref-note {{constructor inherited 
from base class 'YetAnotherBase' cannot be used in a constant expression}} \
-   // expected-error {{must be initialized 
by a constant expression}}
-   // FIXME: Missing reason for rejection.
+   // expected-error {{must be initialized 
by a constant expression}} \
+   // expected-note {{constructor 
inherited from base class 'YetAnotherBase' cannot be used in a constant 
expression}}
 };
 
 namespace EmptyCtor {
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -207,13 +207,15 @@
   // ref-note {{declared const here}}
 int a;
   public:
-constexpr Foo() {
+constexpr Foo() { // expected-note {{declared here}}
   this->a = 10;
   T = 13; // expected-error {{cannot assign to non-static data member 'T' 
with const-qualified type}} \
   // ref-error {{cannot assign to non-static data member 'T' with 
const-qualified type}}
 }
   };
   constexpr Foo F; // expected-error {{must be initialized by a constant 
expression}} \
+   // FIXME: The following note is wrong. \
+   // expected-note {{undefined constructor 'Foo' cannot be 
used in a constant expression}} \
// ref-error {{must be initialized by a constant 
expression}}
 
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1350,7 +1350,7 @@
   if (const auto CtorExpr = dyn_cast(Initializer)) {
 const Function *Func = getFunction(CtorExpr->getConstructor());
 
-if (!Func || !Func->isConstexpr())
+if (!Func)
   return false;
 
 // The This pointer is already on the stack because this is an initializer,


Index: clang/test/AST/Interp/records.cpp

[PATCH] D145841: [clang][Interp] Fix diagnostics for calling non-constexpr constructors

2023-03-23 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




Comment at: clang/test/AST/Interp/records.cpp:353
   struct YetAnotherDerived : YetAnotherBase {
-using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}}
+using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}} 
expected-note {{declared here}}
 int OtherVal;




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

https://reviews.llvm.org/D145841

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


[PATCH] D145841: [clang][Interp] Fix diagnostics for calling non-constexpr constructors

2023-03-19 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D145841

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


[PATCH] D145841: [clang][Interp] Fix diagnostics for calling non-constexpr constructors

2023-03-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 504406.

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

https://reviews.llvm.org/D145841

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -308,7 +308,7 @@
 };
 
 namespace DeriveFailures {
-  struct Base { // ref-note 2{{declared here}}
+  struct Base { // ref-note 2{{declared here}} expected-note {{declared here}}
 int Val;
   };
 
@@ -316,13 +316,15 @@
 int OtherVal;
 
 constexpr Derived(int i) : OtherVal(i) {} // ref-error {{never produces a 
constant expression}} \
-  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
+  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}} \
+  // expected-note {{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
   };
 
   constexpr Derived D(12); // ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{in call to 'Derived(12)'}} \
// ref-note {{declared here}} \
-   // expected-error {{must be initialized by a 
constant expression}}
+   // expected-error {{must be initialized by a 
constant expression}} \
+   // expected-note {{in call to 'Derived(12)'}}
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant 
expression}} \
  // ref-note {{initializer of 'D' is not a 
constant expression}} \
  // expected-error {{not an integral constant 
expression}} \
@@ -348,7 +350,7 @@
   };
 
   struct YetAnotherDerived : YetAnotherBase {
-using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}}
+using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}} 
expected-note {{declared here}}
 int OtherVal;
 
 constexpr bool doit() const { return Val == OtherVal; }
@@ -356,8 +358,8 @@
 
   constexpr YetAnotherDerived Oops(0); // ref-error {{must be initialized by a 
constant expression}} \
// ref-note {{constructor inherited 
from base class 'YetAnotherBase' cannot be used in a constant expression}} \
-   // expected-error {{must be initialized 
by a constant expression}}
-   // FIXME: Missing reason for rejection.
+   // expected-error {{must be initialized 
by a constant expression}} \
+   // expected-note {{constructor 
inherited from base class 'YetAnotherBase' cannot be used in a constant 
expression}}
 };
 
 namespace EmptyCtor {
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -207,13 +207,15 @@
   // ref-note {{declared const here}}
 int a;
   public:
-constexpr Foo() {
+constexpr Foo() { // expected-note {{declared here}}
   this->a = 10;
   T = 13; // expected-error {{cannot assign to non-static data member 'T' 
with const-qualified type}} \
   // ref-error {{cannot assign to non-static data member 'T' with 
const-qualified type}}
 }
   };
   constexpr Foo F; // expected-error {{must be initialized by a constant 
expression}} \
+   // FIXME: The following note is wrong. \
+   // expected-note {{undefined constructor 'Foo' cannot be 
used in a constant expression}} \
// ref-error {{must be initialized by a constant 
expression}}
 
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1376,7 +1376,7 @@
   if (const auto CtorExpr = dyn_cast(Initializer)) {
 const Function *Func = getFunction(CtorExpr->getConstructor());
 
-if (!Func || !Func->isConstexpr())
+if (!Func)
   return false;
 
 // The This pointer is already on the stack because this is an initializer,


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -308,7 +308,7 @@
 };
 
 namespace DeriveFailures {
-  struct Base { // ref-note 2{{declared here}}
+  struct Base { // ref-note 2{{declared here}} expected-note {{declared here}}
 int Val;
   };
 
@@ -316,13 +316,15 @@

[PATCH] D145841: [clang][Interp] Fix diagnostics for calling non-constexpr constructors

2023-03-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145841

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -308,7 +308,7 @@
 };
 
 namespace DeriveFailures {
-  struct Base { // ref-note 2{{declared here}}
+  struct Base { // ref-note 2{{declared here}} expected-note {{declared here}}
 int Val;
   };
 
@@ -316,13 +316,15 @@
 int OtherVal;
 
 constexpr Derived(int i) : OtherVal(i) {} // ref-error {{never produces a 
constant expression}} \
-  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
+  // ref-note 2{{non-constexpr 
constructor 'Base' cannot be used in a constant expression}} \
+  // expected-note {{non-constexpr 
constructor 'Base' cannot be used in a constant expression}}
   };
 
   constexpr Derived D(12); // ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{in call to 'Derived(12)'}} \
// ref-note {{declared here}} \
-   // expected-error {{must be initialized by a 
constant expression}}
+   // expected-error {{must be initialized by a 
constant expression}} \
+   // expected-note {{in call to 'Derived(12)'}}
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant 
expression}} \
  // ref-note {{initializer of 'D' is not a 
constant expression}} \
  // expected-error {{not an integral constant 
expression}} \
@@ -348,7 +350,7 @@
   };
 
   struct YetAnotherDerived : YetAnotherBase {
-using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}}
+using YetAnotherBase::YetAnotherBase; //ref-note {{declared here}} 
expected-note {{declared here}}
 int OtherVal;
 
 constexpr bool doit() const { return Val == OtherVal; }
@@ -356,8 +358,8 @@
 
   constexpr YetAnotherDerived Oops(0); // ref-error {{must be initialized by a 
constant expression}} \
// ref-note {{constructor inherited 
from base class 'YetAnotherBase' cannot be used in a constant expression}} \
-   // expected-error {{must be initialized 
by a constant expression}}
-   // FIXME: Missing reason for rejection.
+   // expected-error {{must be initialized 
by a constant expression}} \
+   // expected-note {{constructor 
inherited from base class 'YetAnotherBase' cannot be used in a constant 
expression}}
 };
 
 namespace EmptyCtor {
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -207,13 +207,15 @@
   // ref-note {{declared const here}}
 int a;
   public:
-constexpr Foo() {
+constexpr Foo() { // expected-note {{declared here}}
   this->a = 10;
   T = 13; // expected-error {{cannot assign to non-static data member 'T' 
with const-qualified type}} \
   // ref-error {{cannot assign to non-static data member 'T' with 
const-qualified type}}
 }
   };
   constexpr Foo F; // expected-error {{must be initialized by a constant 
expression}} \
+   // FIXME: The following note is wrong.
+   // expected-note {{undefined constructor 'Foo' cannot be 
used in a constant expression}} \
// ref-error {{must be initialized by a constant 
expression}}
 
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1376,7 +1376,7 @@
   if (const auto CtorExpr = dyn_cast(Initializer)) {
 const Function *Func = getFunction(CtorExpr->getConstructor());
 
-if (!Func || !Func->isConstexpr())
+if (!Func)
   return false;
 
 // The This pointer is already on the stack because this is an initializer,


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -308,7 +308,7 @@
 };
 
 namespace DeriveFailures {