[clang] [Clang] Diagnose invalid non-dependent calls in dependent contexts. (PR #190965)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 8 05:55:14 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Corentin Jabot (cor3ntin)
<details>
<summary>Changes</summary>
We were bailing out from checking calls expressions in a dependent context, but if the expression itself was not dependent it's never checked again.
Fixes #<!-- -->135694
---
Full diff: https://github.com/llvm/llvm-project/pull/190965.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+1-1)
- (modified) clang/lib/Sema/SemaChecking.cpp (+5-2)
- (added) clang/test/SemaCXX/gh135694.cpp (+22)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2da7175b51ea3..30b3b05eb9f5c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -440,7 +440,7 @@ Bug Fixes to C++ Support
- Inherited constructors in ``dllexport`` classes are now exported for ABI-compatible cases, matching
MSVC behavior. Constructors with variadic arguments or callee-cleanup parameters are not yet supported
and produce a warning. (#GH162640)
-
+- Correctly diagnose invalid non-dependent calls in dependent contexts. (#GH135694)
- Fix initialization of GRO when GRO-return type mismatches, as part of CWG2563. (#GH98744)
- Fix an error using an initializer list with array new for a type that is not default-constructible. (#GH81157)
- We no longer consider conversion operators when copy-initializing from the same type. This was non
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index d53c3b6ab2674..b2288ff9b26d0 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4171,8 +4171,11 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
const Expr *ThisArg, ArrayRef<const Expr *> Args,
bool IsMemberFunction, SourceLocation Loc,
SourceRange Range, VariadicCallType CallType) {
- // FIXME: We should check as much as we can in the template definition.
- if (CurContext->isDependentContext())
+
+ if ((ThisArg && ThisArg->isInstantiationDependent()) ||
+ llvm::any_of(Args, [](const Expr *E) {
+ return E && E->isInstantiationDependent();
+ }))
return;
// Printf and scanf checking.
diff --git a/clang/test/SemaCXX/gh135694.cpp b/clang/test/SemaCXX/gh135694.cpp
new file mode 100644
index 0000000000000..9d77213af2b65
--- /dev/null
+++ b/clang/test/SemaCXX/gh135694.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++20 %s
+
+namespace GH135694_1 {
+
+void a(...);
+template<typename T> void b() {
+ decltype(a(void())) *p; // expected-error {{cannot pass expression of type 'void' to variadic function}}
+}
+void c() { b<void>(); }
+}
+
+
+namespace GH135694_2 {
+
+void a(...);
+template<typename T>
+bool b() {
+ return requires { a(a(1)); }; // expected-error {{cannot pass expression of type 'void' to variadic function}}
+}
+bool c() { return b<void>(); }
+
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/190965
More information about the cfe-commits
mailing list