Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A compound literal does not yield an lvalue #25798

Closed
llvmbot opened this issue Nov 6, 2015 · 2 comments
Closed

A compound literal does not yield an lvalue #25798

llvmbot opened this issue Nov 6, 2015 · 2 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema" invalid Resolved as invalid, i.e. not a bug

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 6, 2015

Bugzilla Link 25424
Resolution INVALID
Resolved on Nov 05, 2015 18:16
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

Given

template <class A, class B> struct IsSame { static constexpr bool value = false; constexpr operator bool () const { return false; } };
template 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) (331a8c8)
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

@llvmbot
Copy link
Collaborator Author

llvmbot commented Nov 6, 2015

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

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Nov 6, 2015

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]'.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema" invalid Resolved as invalid, i.e. not a bug
Projects
None yet
Development

No branches or pull requests

1 participant