]> granicus.if.org Git - clang/commitdiff
initialization of references should not do default fn/array promotions.
authorChris Lattner <sabre@nondot.org>
Tue, 16 Oct 2007 02:55:40 +0000 (02:55 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 16 Oct 2007 02:55:40 +0000 (02:55 +0000)
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
test/Sema/cxx-references.cpp

index 8ee0913f99382281d45f95bbddeb38dca570f2e5..046b92bb076a10d2e1468205f913b8e2e4181abf 100644 (file)
@@ -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;
   
index 74ad3103953ef7df4c5c7b02c2d94a59d54c916a..a1c3eb5518de8a83b72ac11da8c67fb0ee41caab 100644 (file)
@@ -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;
+}