LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 25424 - A compound literal does not yield an lvalue
Summary: A compound literal does not yield an lvalue
Status: RESOLVED INVALID
Alias: None
Product: clang
Classification: Unclassified
Component: Frontend (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-05 18:02 PST by Andrey V
Modified: 2015-11-05 18:16 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey V 2015-11-05 18:02:24 PST
Given

template <class A, class B> struct IsSame { static constexpr bool value = false; constexpr operator bool () const { return false; } };
template <class A> struct IsSame<A,A> { static constexpr bool value = true; constexpr operator bool () const { return true; } };
static_assert(IsSame<decltype(((const char []){ "string"})), const char (&) [7]>::value, "cxl1");

the test-case should pass, since C99/11 states in 6.5.2.5p4 that compound literals return lvalues. Clang preserves the prvalue-ness of the string literal.

Invocation:
clang++ -std=c++11 aa.cc

Clang version:
gentoo-x64 ~ # clang++ -v
clang version 3.8.0 (6215dbd9a8bf16e34b9b7a0cfda3d17e629a2d8d) (331a8c8a870f582385e659dc8785c7ba522136f5)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/5.1.0
Comment 1 Andrey V 2015-11-05 18:10:58 PST
sorry, invocation is clang++ -std=c++11 -c
Alternately, adding `int main(){}` to the testcase should suffice.

Otherwise, there's the linker error about missing `main`. :)
Comment 2 Richard Smith 2015-11-05 18:16:12 PST
Compound literals are not part of C++. Clang allows them as an extension, with the following semantics:

  (T){init}

means the same thing as

  T{init}

Thus the compound literal, in this case, a prvalue of type 'const char[7]'.