Boost logo

Boost :

Subject: Re: [boost] Boost.Exception and constexpr
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2013-01-10 09:53:24


On 10.01.2013 15:46, Andrey Semashev wrote:
> template< typename T, unsigned int n >
> struct array
> {
> constexpr T at(unsigned int i) const
> {
> return i < n ? T() : throw 0;
> }
> };
>
> template< int m >
> struct check
> {
> static int get() { return m; }
> };
>
> int main(int, char*[])
> {
> array< int, 5 > arr;
> check< arr.at(10) > a;
> return a::get();
> }
>
> produces the following error:
>
> ./constexpr_test.cpp: In function ‘int main(int, char**)’:
> ./constexpr_test.cpp:19:21: in constexpr expansion of ‘arr.array<T,
> n>::at [with T = int, unsigned int n = 5u](10u)’
> ./constexpr_test.cpp:6:36: error: expression ‘<throw-expression>’ is
> not a constant-expression
This is expected. Not ideal, but that's what you currently get from
constexpr-capable compilers. Clang isn't much different.
> ./constexpr_test.cpp:19:26: error: invalid type in declaration before ‘;’ token
This is just stupid.
> ./constexpr_test.cpp:20:12: error: ‘a’ is not a class, namespace, or enumeration
This is your own fault. You want a.get(), not a::get(). Or maybe the
line above was supposed to be a typedef?

Sebastian


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk