Skip to content

[clang][Interp] Point 'declared here' note of invalid fns to definition #102031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Aug 5, 2024

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Aug 5, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 5, 2024

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/102031.diff

2 Files Affected:

  • (modified) clang/lib/AST/Interp/Interp.cpp (+6-1)
  • (modified) clang/test/AST/Interp/cxx20.cpp (+17)
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 0252dd0d32699..0f72b860ddad7 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -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);
diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index da80454b7a820..27dbd2818be60 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -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}}
+}

@tbaederr tbaederr merged commit 421c3fe into llvm:main Aug 6, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants