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

            Bug ID: 38266
           Summary: taking address of temporary array
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: zhong...@pku.org.cn
                CC: dgre...@apple.com, llvm-bugs@lists.llvm.org

The code is as follow:

#include <stdio.h>

void fn(int arr[])
{
 for (int j = 0; j < 5; ++j)
 printf("%d: %d\n", j, arr[j]);
}

int main()
{
 fn((int[]) { 41, 42, 43, 44, 45 } );
 return 0;
}

clang++ accepts it but g++ rejects it:

code5.cpp: In function 'int main()':
code5.cpp:11:13: error: taking address of temporary array
  fn((int[]) { 41, 42, 43, 44, 45 } );
             ^~~~~~~~~~~~~~~~~~~~~~

Here is another code sample:

extern "C" int printf(const char*, ...);
int main() { 
 using A = int[1];
 printf("%p\n", A{1} );
}

clang++ again accepts it, but g++ rejects it:


code6.cpp: In function 'int main()':
code6.cpp:4:17: error: taking address of temporary array
  printf("%p\n", A{1} );
                 ^~~~

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to