[llvm-bugs] [Bug 38266] New: taking address of temporary array

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jul 22 17:15:50 PDT 2018


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: 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:

#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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180723/4f228239/attachment.html>


More information about the llvm-bugs mailing list