[LLVMbugs] [Bug 9554] New: Suboptimal error message for invalid access to struct member in array

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Mar 25 12:44:17 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=9554

           Summary: Suboptimal error message for invalid access to struct
                    member in array
           Product: clang
           Version: unspecified
          Platform: Macintosh
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jonathan.sauer at gmx.de
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


The following (invalid) code:

struct V {
    float x, y, z; 
};

struct A {
    V    xyz[1];
};


int main(int, char**)
{
    A    b;
    // Should be b.xyz[0].x = 1.0f;
    b.xyz.x = 1.0f;
}


generates the following error message:

$ /opt/bin/clang clang.cpp
clang.cpp:14:7: error: member reference type 'V *' is a pointer; maybe you
meant to use '->'?
        b.xyz.x = 1.0f;
        ~~~~~^
             ->
1 error generated.


This message is not very helpful, especially since the fixit is certainly not
what the user desires (although it is syntactically valid). It should be
something like "member reference type 'V[1]' is an array; maybe you meant to
use '[<index>].'?"

Although arrays decay to pointers in some situations in C/C++, I think clang in
general should avoid referring to the decayed type in error messages, as it is
less clear.


My version of clang:

$ /opt/bin/clang --version
clang version 3.0 (trunk 127993)
Target: x86_64-apple-darwin10
Thread model: posix

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list