Skip to content

Commit

Permalink
[clang][Interp] Point 'declared here' note of invalid fns to definiti…
Browse files Browse the repository at this point in the history
…on (llvm#102031)
  • Loading branch information
tbaederr authored Aug 6, 2024
1 parent 265fbfa commit 421c3fe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion clang/lib/AST/Interp/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,12 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {

S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
<< DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
S.Note(DiagDecl->getLocation(), diag::note_declared_at);

if (DiagDecl->getDefinition())
S.Note(DiagDecl->getDefinition()->getLocation(),
diag::note_declared_at);
else
S.Note(DiagDecl->getLocation(), diag::note_declared_at);
}
} else {
S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
Expand Down
17 changes: 17 additions & 0 deletions clang/test/AST/Interp/cxx20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,3 +841,20 @@ namespace VariadicCallOperator {
}
constexpr int A = foo();
}

namespace DefinitionLoc {

struct NonConstexprCopy {
constexpr NonConstexprCopy() = default;
NonConstexprCopy(const NonConstexprCopy &);
constexpr NonConstexprCopy(NonConstexprCopy &&) = default;

int n = 42;
};

NonConstexprCopy::NonConstexprCopy(const NonConstexprCopy &) = default; // both-note {{here}}

constexpr NonConstexprCopy ncc1 = NonConstexprCopy(NonConstexprCopy());
constexpr NonConstexprCopy ncc2 = ncc1; // both-error {{constant expression}} \
// both-note {{non-constexpr constructor}}
}

0 comments on commit 421c3fe

Please sign in to comment.