llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> Let the declared_at note point to the declaration in that case. --- Full diff: https://github.com/llvm/llvm-project/pull/208679.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.cpp (+4-2) - (modified) clang/test/AST/ByteCode/invalid.cpp (+9) ``````````diff diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index b2af27fc88542..0adcdfe6e78c9 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1110,8 +1110,10 @@ static bool diagnoseCallableDecl(InterpState &S, CodePtr OpPC, diag::note_constexpr_invalid_function, 1) << DiagDecl->isConstexpr() << (bool)CD << DiagDecl; - if (DiagDecl->getDefinition()) - S.Note(DiagDecl->getDefinition()->getLocation(), diag::note_declared_at); + const FunctionDecl *Definition; + const Stmt *Body = DiagDecl->getBody(Definition); + if (Body && Definition) + S.Note(Definition->getLocation(), diag::note_declared_at); else S.Note(DiagDecl->getLocation(), diag::note_declared_at); } diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp index e79b698a32719..930565181b202 100644 --- a/clang/test/AST/ByteCode/invalid.cpp +++ b/clang/test/AST/ByteCode/invalid.cpp @@ -218,3 +218,12 @@ namespace InvalidVirtualCast { static_assert((X *)(Y *)&z, ""); // both-error {{not an integral constant expression}} \ // both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}} } + +namespace DefinitionInBody { + int foo(); // both-note {{declared here}} + int foo() { + static_assert(foo() == 1); // both-error {{not an integral constant expression}} \ + // both-note {{non-constexpr function 'foo' cannot be used in a constant expression}} + return 5; + } +} `````````` </details> https://github.com/llvm/llvm-project/pull/208679 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
