https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/190965

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

>From 258708c9d1da7b4515c401f11d2e91c5da4f08b3 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <[email protected]>
Date: Wed, 8 Apr 2026 14:51:51 +0200
Subject: [PATCH] [Clang] Diagnose invalid non-depemdent calls in dependent
 contexts.

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
---
 clang/docs/ReleaseNotes.rst     |  2 +-
 clang/lib/Sema/SemaChecking.cpp |  7 +++++--
 clang/test/SemaCXX/gh135694.cpp | 22 ++++++++++++++++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/gh135694.cpp

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>(); }
+
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to