From 943140ee64e979325d25084bf4d768896601a7ce Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 16 Oct 2007 02:55:40 +0000 Subject: [PATCH] initialization of references should not do default fn/array promotions. This fixes a bug Anders noticed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43024 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/SemaExpr.cpp | 8 ++++++-- test/Sema/cxx-references.cpp | 13 +++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 8ee0913f99..046b92bb07 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -1056,11 +1056,15 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { Sema::AssignmentCheckResult Sema::CheckSingleAssignmentConstraints(QualType lhsType, Expr *&rExpr) { - // This check seems unnatural, however it is necessary to insure the proper + // This check seems unnatural, however it is necessary to ensure the proper // conversion of functions/arrays. If the conversion were done for all // DeclExpr's (created by ActOnIdentifierExpr), it would mess up the unary // expressions that surpress this implicit conversion (&, sizeof). - DefaultFunctionArrayConversion(rExpr); + // + // Suppress this for references: C99 8.5.3p5. FIXME: revisit when references + // are better understood. + if (!lhsType->isReferenceType()) + DefaultFunctionArrayConversion(rExpr); Sema::AssignmentCheckResult result; diff --git a/test/Sema/cxx-references.cpp b/test/Sema/cxx-references.cpp index 74ad310395..a1c3eb5518 100644 --- a/test/Sema/cxx-references.cpp +++ b/test/Sema/cxx-references.cpp @@ -1,12 +1,13 @@ // RUN: clang -fsyntax-only %s int g(int); -#if 0 void f() { int i; int &r = i; r = 1; +#if 0 // FIXME: &ref not right yet int *p = &r; +#endif int &rr = r; int (&rg)(int) = g; rg(i); @@ -18,4 +19,12 @@ void f() { P[1] = 1; } -#endif +typedef int t[1]; +void test2() { + t a; + t& b = a; + + + int c[3]; + int (&rc)[3] = c; +} -- 2.40.0