[clang] abd5ee9 - Revert "[Clang] Diagnose invalid function types in dependent contexts (#138731)" (#139176)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 8 16:56:51 PDT 2025
Author: Matheus Izvekov
Date: 2025-05-08T20:56:48-03:00
New Revision: abd5ee9355c2d3fd0df8bb0e57a0f2cf2f9fb435
URL: https://github.com/llvm/llvm-project/commit/abd5ee9355c2d3fd0df8bb0e57a0f2cf2f9fb435
DIFF: https://github.com/llvm/llvm-project/commit/abd5ee9355c2d3fd0df8bb0e57a0f2cf2f9fb435.diff
LOG: Revert "[Clang] Diagnose invalid function types in dependent contexts (#138731)" (#139176)
This reverts commit cf9b4d1e7961214deabd99a9fc3b1d4c9e78a71f.
Causes breakages as reported here:
https://github.com/llvm/llvm-project/pull/138731#issuecomment-2864298000
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaTemplate/fun-template-def.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52fa8df4d51d1..1f0dbe565db6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -566,7 +566,7 @@ Bug Fixes in This Version
- Fixed a bug where an attribute before a ``pragma clang attribute`` or
``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses
the invalid attribute location appropriately. (#GH137861)
-- Fixed a crash when a malformed ``_Pragma`` directive appears as part of an
+- Fixed a crash when a malformed ``_Pragma`` directive appears as part of an
``#include`` directive. (#GH138094)
- Fixed a crash during constant evaluation involving invalid lambda captures
(#GH138832)
@@ -675,7 +675,6 @@ Bug Fixes to C++ Support
- Fixed an assertion when trying to constant-fold various builtins when the argument
referred to a reference to an incomplete type. (#GH129397)
- Fixed a crash when a cast involved a parenthesized aggregate initialization in dependent context. (#GH72880)
-- Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852)
- No longer crashes when instantiating invalid variable template specialization
whose type depends on itself. (#GH51347), (#GH55872)
- Improved parser recovery of invalid requirement expressions. In turn, this
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 57135adf714ce..deb8d2edfc5c9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6550,15 +6550,6 @@ ExprResult Sema::ActOnCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
return Call;
}
-// Any type that could be used to form a callable expression
-static bool MayBeFunctionType(const ASTContext &Context, QualType T) {
- return T == Context.BoundMemberTy || T == Context.UnknownAnyTy ||
- T == Context.BuiltinFnTy || T == Context.OverloadTy ||
- T->isFunctionType() || T->isFunctionReferenceType() ||
- T->isMemberFunctionPointerType() || T->isFunctionPointerType() ||
- T->isBlockPointerType() || T->isRecordType();
-}
-
ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
MultiExprArg ArgExprs, SourceLocation RParenLoc,
Expr *ExecConfig, bool IsExecConfig,
@@ -6612,15 +6603,6 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
*this, dyn_cast<UnresolvedMemberExpr>(Fn->IgnoreParens()),
Fn->getBeginLoc());
- // If the type of the function itself is not dependent
- // check that it is a reasonable as a function, as type deduction
- // later assume the CallExpr has a sensible TYPE.
- if (!Fn->getType()->isDependentType() &&
- !MayBeFunctionType(Context, Fn->getType()))
- return ExprError(
- Diag(LParenLoc, diag::err_typecheck_call_not_function)
- << Fn->getType() << Fn->getSourceRange());
-
return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy,
VK_PRValue, RParenLoc, CurFPFeatureOverrides());
}
diff --git a/clang/test/SemaTemplate/fun-template-def.cpp b/clang/test/SemaTemplate/fun-template-def.cpp
index 716296e72bc44..de77901b5b601 100644
--- a/clang/test/SemaTemplate/fun-template-def.cpp
+++ b/clang/test/SemaTemplate/fun-template-def.cpp
@@ -1,7 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
// Tests that dependent expressions are always allowed, whereas non-dependent
// are checked as usual.
@@ -33,7 +32,7 @@ T f1(T t1, U u1, int i1, T** tpp)
i1 = t1[u1];
i1 *= t1;
- i1(u1, t1); // expected-error {{called object type 'int' is not a function or function pointer}}
+ i1(u1, t1); // error
u1(i1, t1);
U u2 = (T)i1;
@@ -61,51 +60,3 @@ void f3() {
f2<int*>(0);
f2<int>(0); // expected-error {{no matching function for call to 'f2'}}
}
-
-#if __cplusplus >= 202002L
-namespace GH138657 {
-template <auto V> // #gh138657-template-head
-class meta {};
-template<int N>
-class meta<N()> {}; // expected-error {{called object type 'int' is not a function or function point}}
-
-template<int N[1]>
-class meta<N()> {}; // expected-error {{called object type 'int *' is not a function or function point}}
-
-template<char* N>
-class meta<N()> {}; // expected-error {{called object type 'char *' is not a function or function point}}
-
-struct S {};
-template<S>
-class meta<S()> {}; // expected-error {{template argument for non-type template parameter is treated as function type 'S ()'}}
- // expected-note@#gh138657-template-head {{template parameter is declared here}}
-
-}
-
-namespace GH115725 {
-template<auto ...> struct X {};
-template<typename T, typename ...Ts> struct A {
- template<Ts ...Ns, T *...Ps>
- A(X<0(Ps)...>, Ts (*...qs)[Ns]);
- // expected-error at -1{{called object type 'int' is not a function or function pointer}}
-
-};
-}
-
-namespace GH68852 {
-template <auto v>
-struct constexpr_value {
- template <class... Ts>
- constexpr constexpr_value<v(Ts::value...)> call(Ts...) {
- //expected-error at -1 {{called object type 'int' is not a function or function pointer}}
- return {};
- }
-};
-
-template <auto v> constexpr static inline auto c_ = constexpr_value<v>{};
-// expected-note at -1 {{in instantiation of template}}
-auto k = c_<1>; // expected-note {{in instantiation of variable}}
-
-}
-
-#endif
More information about the cfe-commits
mailing list