Skip to content

Commit 421c3fe

Browse files
authored
[clang][Interp] Point 'declared here' note of invalid fns to definition (llvm#102031)
1 parent 265fbfa commit 421c3fe

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,12 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
628628

629629
S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
630630
<< DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
631-
S.Note(DiagDecl->getLocation(), diag::note_declared_at);
631+
632+
if (DiagDecl->getDefinition())
633+
S.Note(DiagDecl->getDefinition()->getLocation(),
634+
diag::note_declared_at);
635+
else
636+
S.Note(DiagDecl->getLocation(), diag::note_declared_at);
632637
}
633638
} else {
634639
S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);

clang/test/AST/Interp/cxx20.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,20 @@ namespace VariadicCallOperator {
841841
}
842842
constexpr int A = foo();
843843
}
844+
845+
namespace DefinitionLoc {
846+
847+
struct NonConstexprCopy {
848+
constexpr NonConstexprCopy() = default;
849+
NonConstexprCopy(const NonConstexprCopy &);
850+
constexpr NonConstexprCopy(NonConstexprCopy &&) = default;
851+
852+
int n = 42;
853+
};
854+
855+
NonConstexprCopy::NonConstexprCopy(const NonConstexprCopy &) = default; // both-note {{here}}
856+
857+
constexpr NonConstexprCopy ncc1 = NonConstexprCopy(NonConstexprCopy());
858+
constexpr NonConstexprCopy ncc2 = ncc1; // both-error {{constant expression}} \
859+
// both-note {{non-constexpr constructor}}
860+
}

0 commit comments

Comments
 (0)