[llvm-bugs] [Bug 37925] New: invalid types 'const float2 {aka const float}[unsigned int]' for array subscript

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 25 01:56:22 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37925

            Bug ID: 37925
           Summary: invalid types 'const float2 {aka const float}[unsigned
                    int]' for array subscript
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zhonghao at pku.org.cn
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The code is as follow:

typedef float float2 __attribute__( ( ext_vector_type( 2 ) ) );

const float &get( const float2 &vec, unsigned int index ) {
 return vec[ index ];
}

int main() {
 float2 a;
 get( a, 1 );
}

clang produces a warning message:
warning: returning reference to local temporary object
      [-Wreturn-stack-address]
 return vec[ index ];
        ^~~~~~~~~~~~

g++ rejects the code: 
code0.c.cpp:1:62: warning: 'ext_vector_type' attribute directive ignored
[-Wattributes]
 typedef float float2 __attribute__( ( ext_vector_type( 2 ) ) );
                                                              ^
code0.c.cpp: In function 'const float& get(const float2&, unsigned int)':
code0.c.cpp:4:20: error: invalid types 'const float2 {aka const float}[unsigned
int]' for array subscript
  return vec[ index ];


It seems that the diagnose of gcc is more reasonable, right?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180625/47eddce4/attachment.html>


More information about the llvm-bugs mailing list