Skip to content

Commit abd5ee9

Browse files
authored
Revert "[Clang] Diagnose invalid function types in dependent contexts (#138731)" (#139176)
This reverts commit cf9b4d1. Causes breakages as reported here: #138731 (comment)
1 parent 02139b1 commit abd5ee9

File tree

3 files changed

+2
-70
lines changed

3 files changed

+2
-70
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ Bug Fixes in This Version
566566
- Fixed a bug where an attribute before a ``pragma clang attribute`` or
567567
``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses
568568
the invalid attribute location appropriately. (#GH137861)
569-
- Fixed a crash when a malformed ``_Pragma`` directive appears as part of an
569+
- Fixed a crash when a malformed ``_Pragma`` directive appears as part of an
570570
``#include`` directive. (#GH138094)
571571
- Fixed a crash during constant evaluation involving invalid lambda captures
572572
(#GH138832)
@@ -675,7 +675,6 @@ Bug Fixes to C++ Support
675675
- Fixed an assertion when trying to constant-fold various builtins when the argument
676676
referred to a reference to an incomplete type. (#GH129397)
677677
- Fixed a crash when a cast involved a parenthesized aggregate initialization in dependent context. (#GH72880)
678-
- Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852)
679678
- No longer crashes when instantiating invalid variable template specialization
680679
whose type depends on itself. (#GH51347), (#GH55872)
681680
- Improved parser recovery of invalid requirement expressions. In turn, this

clang/lib/Sema/SemaExpr.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6550,15 +6550,6 @@ ExprResult Sema::ActOnCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
65506550
return Call;
65516551
}
65526552

6553-
// Any type that could be used to form a callable expression
6554-
static bool MayBeFunctionType(const ASTContext &Context, QualType T) {
6555-
return T == Context.BoundMemberTy || T == Context.UnknownAnyTy ||
6556-
T == Context.BuiltinFnTy || T == Context.OverloadTy ||
6557-
T->isFunctionType() || T->isFunctionReferenceType() ||
6558-
T->isMemberFunctionPointerType() || T->isFunctionPointerType() ||
6559-
T->isBlockPointerType() || T->isRecordType();
6560-
}
6561-
65626553
ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
65636554
MultiExprArg ArgExprs, SourceLocation RParenLoc,
65646555
Expr *ExecConfig, bool IsExecConfig,
@@ -6612,15 +6603,6 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
66126603
*this, dyn_cast<UnresolvedMemberExpr>(Fn->IgnoreParens()),
66136604
Fn->getBeginLoc());
66146605

6615-
// If the type of the function itself is not dependent
6616-
// check that it is a reasonable as a function, as type deduction
6617-
// later assume the CallExpr has a sensible TYPE.
6618-
if (!Fn->getType()->isDependentType() &&
6619-
!MayBeFunctionType(Context, Fn->getType()))
6620-
return ExprError(
6621-
Diag(LParenLoc, diag::err_typecheck_call_not_function)
6622-
<< Fn->getType() << Fn->getSourceRange());
6623-
66246606
return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy,
66256607
VK_PRValue, RParenLoc, CurFPFeatureOverrides());
66266608
}
Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
22
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
33
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4-
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
54

65
// Tests that dependent expressions are always allowed, whereas non-dependent
76
// are checked as usual.
@@ -33,7 +32,7 @@ T f1(T t1, U u1, int i1, T** tpp)
3332
i1 = t1[u1];
3433
i1 *= t1;
3534

36-
i1(u1, t1); // expected-error {{called object type 'int' is not a function or function pointer}}
35+
i1(u1, t1); // error
3736
u1(i1, t1);
3837

3938
U u2 = (T)i1;
@@ -61,51 +60,3 @@ void f3() {
6160
f2<int*>(0);
6261
f2<int>(0); // expected-error {{no matching function for call to 'f2'}}
6362
}
64-
65-
#if __cplusplus >= 202002L
66-
namespace GH138657 {
67-
template <auto V> // #gh138657-template-head
68-
class meta {};
69-
template<int N>
70-
class meta<N()> {}; // expected-error {{called object type 'int' is not a function or function point}}
71-
72-
template<int N[1]>
73-
class meta<N()> {}; // expected-error {{called object type 'int *' is not a function or function point}}
74-
75-
template<char* N>
76-
class meta<N()> {}; // expected-error {{called object type 'char *' is not a function or function point}}
77-
78-
struct S {};
79-
template<S>
80-
class meta<S()> {}; // expected-error {{template argument for non-type template parameter is treated as function type 'S ()'}}
81-
// expected-note@#gh138657-template-head {{template parameter is declared here}}
82-
83-
}
84-
85-
namespace GH115725 {
86-
template<auto ...> struct X {};
87-
template<typename T, typename ...Ts> struct A {
88-
template<Ts ...Ns, T *...Ps>
89-
A(X<0(Ps)...>, Ts (*...qs)[Ns]);
90-
// expected-error@-1{{called object type 'int' is not a function or function pointer}}
91-
92-
};
93-
}
94-
95-
namespace GH68852 {
96-
template <auto v>
97-
struct constexpr_value {
98-
template <class... Ts>
99-
constexpr constexpr_value<v(Ts::value...)> call(Ts...) {
100-
//expected-error@-1 {{called object type 'int' is not a function or function pointer}}
101-
return {};
102-
}
103-
};
104-
105-
template <auto v> constexpr static inline auto c_ = constexpr_value<v>{};
106-
// expected-note@-1 {{in instantiation of template}}
107-
auto k = c_<1>; // expected-note {{in instantiation of variable}}
108-
109-
}
110-
111-
#endif

0 commit comments

Comments
 (0)