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

Unable to use std::initializer_list in constant expressions #15489

Closed
DougGregor opened this issue Jan 30, 2013 · 5 comments
Closed

Unable to use std::initializer_list in constant expressions #15489

DougGregor opened this issue Jan 30, 2013 · 5 comments
Labels
bugzilla Issues migrated from bugzilla c++11

Comments

@DougGregor
Copy link
Contributor

Bugzilla Link 15117
Resolution FIXED
Resolved on Jun 12, 2013 17:32
Version trunk
OS All
CC @DougGregor,@zygoloid

Extended Description

The following is well-formed:

#include <initializer_list>
constexpr auto foo{1, 2};

but Clang rejects it with

t2.cpp:3:16: error: constexpr variable 'foo' must be initialized by a constant
expression
constexpr auto foo{1, 2};
^ ~~~~~~

because RecordExprEvaluator::VisitInitListExpr doesn't handle std::initializer_lists. What it should do is create an array and then set the pointer/length fields of the std::initializer_list to point into that array.

@DougGregor
Copy link
Contributor Author

This is also rdar://problem/13096001.

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jan 30, 2013

This was ill-formed in FDIS (initializer_list wasn't a literal type). I guess LWG are adding core language features now? :)

@DougGregor
Copy link
Contributor Author

Sneaky, eh?

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jan 31, 2013

Ugh, our current constant value representation can't handle this in the case where the initializer_list initialization creates additional unnamed static-storage-duration arrays.

We have a similar problem for nested initializer_list objects outside the constant expression evaluator:

:2:56: error: cannot compile this nested global std::initializer_list yet
std::initializer_list<std::initializer_list> x = {{1,2},{3,4,5}};
^~~~~

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 13, 2013

Fixed in r183872.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 4, 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 c++11
Projects
None yet
Development

No branches or pull requests

1 participant