We tried to provide a very nice diagnostic when diagnosing an assignment
to a const int & produced by a function call. However, we cannot always
determine what function was called.
This fixes PR24568.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246014
91177308-0d34-0410-b5e6-
96231b3b80d8
if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
// Function calls
const FunctionDecl *FD = CE->getDirectCallee();
- if (!IsTypeModifiable(FD->getReturnType(), IsDereference)) {
+ if (FD && !IsTypeModifiable(FD->getReturnType(), IsDereference)) {
if (!DiagnosticEmitted) {
S.Diag(Loc, diag::err_typecheck_assign_const) << ExprRange
<< ConstFunction << FD;
h.a = 1; // expected-error {{cannot assign to non-static data member 'a' with const-qualified type 'const int'}}
h.b = 2; // expected-error {{cannot assign to non-static data member 'b' with const-qualified type 'const int &'}}
}
+
+void test() {
+ typedef const int &Func();
+
+ Func &bar();
+ bar()() = 0; // expected-error {{read-only variable is not assignable}}
+}