Code like this:
struct simple { int i; };
void f(void) {
struct simple s[1];
s->i = 1;
}
produces the error:
$ clang -fsyntax-only test.c
test.c:8:6: error: member reference is not a pointer
s->i = 1;
^ ~
1 diagnostic generated.
My understanding is that this is legal as per C99 6.3.2.1 p3:
Except when it is the operand of the sizeof operator or the unary &
operator, or is a
string literal used to initialize an array, an expression that has
type ''array of type'' is
converted to an expression with type ''pointer to type'' that points
to the initial element of
the array object and is not an lvalue.
My attempt at a patch is attached.
Carl.
Index: Sema/SemaExpr.cpp
===================================================================
--- Sema/SemaExpr.cpp (revision 45070)
+++ Sema/SemaExpr.cpp (working copy)
@@ -510,6 +510,9 @@
if (OpKind == tok::arrow) {
if (const PointerType *PT = BaseType->getAsPointerType())
BaseType = PT->getPointeeType();
+ // C99 6.3.2.1 p3 - array can be treated as pointer to initial element
+ else if(const ArrayType *AT = BaseType->getAsArrayType())
+ BaseType = AT->getElementType();
else
return Diag(OpLoc, diag::err_typecheck_member_reference_arrow,
SourceRange(MemberLoc));
_______________________________________________
cfe-dev mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev