Author: Corentin Jabot Date: 2026-04-14T17:29:59+02:00 New Revision: 034d4dcad6396d1241e8262e69871b8d61da7e4f
URL: https://github.com/llvm/llvm-project/commit/034d4dcad6396d1241e8262e69871b8d61da7e4f DIFF: https://github.com/llvm/llvm-project/commit/034d4dcad6396d1241e8262e69871b8d61da7e4f.diff LOG: [Clang] Diagnose invalid non-dependent calls in dependent contexts. (#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 Added: clang/test/SemaCXX/gh135694.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaChecking.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3e2d287d1eb1f..6d7a8631f0d58 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -451,7 +451,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..6948b66e0c04e --- /dev/null +++ b/clang/test/SemaCXX/gh135694.cpp @@ -0,0 +1,31 @@ +// 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>(); } + +} + +namespace GH135694_3 { + +void a(...); +template<typename T, auto F> void b() { + decltype(F(void())) *p; // expected-error {{cannot pass expression of type 'void' to variadic function}} +} +void c() { b<void, a>(); } // expected-note {{in instantiation}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
