File tree Expand file tree Collapse file tree 3 files changed +31
-15
lines changed Expand file tree Collapse file tree 3 files changed +31
-15
lines changed Original file line number Diff line number Diff line change @@ -3181,13 +3181,6 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
3181
3181
if (T->isRecordType ()) {
3182
3182
const CXXConstructorDecl *Ctor = E->getConstructor ();
3183
3183
3184
- // Trivial copy/move constructor. Avoid copy.
3185
- if (Ctor->isDefaulted () && Ctor->isCopyOrMoveConstructor () &&
3186
- Ctor->isTrivial () &&
3187
- E->getArg (0 )->isTemporaryObject (Ctx.getASTContext (),
3188
- T->getAsCXXRecordDecl ()))
3189
- return this ->visitInitializer (E->getArg (0 ));
3190
-
3191
3184
// If we're discarding a construct expression, we still need
3192
3185
// to allocate a variable and call the constructor and destructor.
3193
3186
if (DiscardResult) {
@@ -3203,6 +3196,13 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
3203
3196
return false ;
3204
3197
}
3205
3198
3199
+ // Trivial copy/move constructor. Avoid copy.
3200
+ if (Ctor->isDefaulted () && Ctor->isCopyOrMoveConstructor () &&
3201
+ Ctor->isTrivial () &&
3202
+ E->getArg (0 )->isTemporaryObject (Ctx.getASTContext (),
3203
+ T->getAsCXXRecordDecl ()))
3204
+ return this ->visitInitializer (E->getArg (0 ));
3205
+
3206
3206
// Zero initialization.
3207
3207
if (E->requiresZeroInitialization ()) {
3208
3208
const Record *R = getRecord (E->getType ());
Original file line number Diff line number Diff line change @@ -1084,3 +1084,19 @@ namespace Virtual {
1084
1084
static_assert (l.b == 10 );
1085
1085
static_assert (l.c == 10 );
1086
1086
}
1087
+
1088
+ namespace DiscardedTrivialCXXConstructExpr {
1089
+ struct S {
1090
+ constexpr S (int a) : x(a) {}
1091
+ int x;
1092
+ };
1093
+
1094
+ constexpr int foo (int x) { // ref-error {{never produces a constant expression}}
1095
+ throw S (3 ); // both-note {{not valid in a constant expression}} \
1096
+ // ref-note {{not valid in a constant expression}}
1097
+ return 1 ;
1098
+ }
1099
+
1100
+ constexpr int y = foo(12 ); // both-error {{must be initialized by a constant expression}} \
1101
+ // both-note {{in call to}}
1102
+ }
Original file line number Diff line number Diff line change 1
- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter - std=c++14 -verify=expected,both %s
2
- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter - std=c++17 -verify=expected,both %s
3
- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter - std=c++17 -triple i686 - verify=expected,both %s
4
- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter - std=c++20 -verify=expected,both %s
5
- // RUN: %clang_cc1 -verify=ref,both - std=c++14 %s
6
- // RUN: %clang_cc1 -verify=ref,both - std=c++17 %s
7
- // RUN: %clang_cc1 -verify=ref,both - std=c++17 -triple i686 %s
8
- // RUN: %clang_cc1 -verify=ref,both - std=c++20 %s
1
+ // RUN: %clang_cc1 -std=c++14 -verify=expected,both %s -fexperimental-new-constant-interpreter
2
+ // RUN: %clang_cc1 -std=c++17 -verify=expected,both %s -fexperimental-new-constant-interpreter
3
+ // RUN: %clang_cc1 -std=c++17 -verify=expected,both -triple i686 %s -fexperimental-new-constant-interpreter
4
+ // RUN: %clang_cc1 -std=c++20 -verify=expected,both %s -fexperimental-new-constant-interpreter
5
+ // RUN: %clang_cc1 -std=c++14 -verify=ref,both %s
6
+ // RUN: %clang_cc1 -std=c++17 -verify=ref,both %s
7
+ // RUN: %clang_cc1 -std=c++17 -verify=ref,both - triple i686 %s
8
+ // RUN: %clang_cc1 -std=c++20 -verify=ref,both %s
9
9
10
10
// / Used to crash.
11
11
struct Empty {};
You can’t perform that action at this time.
0 commit comments