Skip to content

Commit 13acb3a

Browse files
committed
[clang][Interp] Don't diagnose alread invalid function decls
They have already been diagnosed before. Also improve that test case.
1 parent 7889090 commit 13acb3a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
462462
if (S.getLangOpts().CPlusPlus11) {
463463
const FunctionDecl *DiagDecl = F->getDecl();
464464

465+
// Invalid decls have been diagnosed before.
466+
if (DiagDecl->isInvalidDecl())
467+
return false;
468+
465469
// If this function is not constexpr because it is an inherited
466470
// non-constexpr constructor, diagnose that directly.
467471
const auto *CD = dyn_cast<CXXConstructorDecl>(DiagDecl);

clang/test/SemaCXX/PR68542.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
2+
// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s -fexperimental-new-constant-interpreter
23

3-
struct S {
4+
struct S { // expected-note {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'S &&' for 1st argument}} \
5+
// expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const S &' for 1st argument}}
46
int e;
57
};
68

79
template<class T>
810
consteval int get_format() {
9-
return nullptr; // expected-error{{cannot initialize return object of type 'int' with an rvalue of type 'std::nullptr_t'}}
11+
return nullptr; // expected-error {{cannot initialize return object of type 'int' with an rvalue of type 'std::nullptr_t'}}
1012
}
1113

1214
template<class T>
1315
constexpr S f(T) noexcept {
14-
return get_format<T>(); // expected-error{{no viable conversion from returned value of type 'int' to function return type 'S'}}
16+
return get_format<T>(); // expected-error {{no viable conversion from returned value of type 'int' to function return type 'S'}}
1517
}
1618

17-
constexpr S x = f(0); // expected-error{{constexpr variable 'x' must be initialized by a constant expression}}
18-
// expected-note@-1{{in instantiation of function template specialization 'f<int>' requested here}}
19-
// expected-note@3{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'S &&' for 1st argument}}
20-
// expected-note@3{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const S &' for 1st argument}}
19+
constexpr S x = f(0); // expected-error {{constexpr variable 'x' must be initialized by a constant expression}} \
20+
// expected-note {{in instantiation of function template specialization 'f<int>' requested here}}

0 commit comments

Comments
 (0)