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 15117 - Unable to use std::initializer_list in constant expressions
Summary: Unable to use std::initializer_list in constant expressions
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++11 (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-30 02:09 PST by Douglas Gregor
Modified: 2013-06-12 17:32 PDT (History)
4 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 Douglas Gregor 2013-01-30 02:09:36 PST
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.
Comment 1 Douglas Gregor 2013-01-30 02:09:46 PST
This is also <rdar://problem/13096001>.
Comment 2 Richard Smith 2013-01-30 14:26:03 PST
This was ill-formed in FDIS (initializer_list wasn't a literal type). I guess LWG are adding core language features now? :)
Comment 3 Douglas Gregor 2013-01-30 15:43:42 PST
Sneaky, eh?
Comment 4 Richard Smith 2013-01-30 17:11:28 PST
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:

<stdin>:2:56: error: cannot compile this nested global std::initializer_list yet
std::initializer_list<std::initializer_list<int>> x = {{1,2},{3,4,5}};
                                                       ^~~~~
Comment 5 Richard Smith 2013-06-12 17:32:24 PDT
Fixed in r183872.