Boost logo

Boost :

Subject: Re: [boost] Boost.Exception and constexpr
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-01-10 14:12:12


On Thu, Jan 10, 2013 at 10:51 PM, Vicente J. Botet Escriba
<vicente.botet_at_[hidden]> wrote:
> Le 10/01/13 19:13, Andrey Semashev a écrit :
>
>> On Thu, Jan 10, 2013 at 9:06 PM, Vicente J. Botet Escriba
>> <vicente.botet_at_[hidden]> wrote:
>>>
>>> Have you tried declaring arr as a constexpr?
>>
>> It doesn't make any difference, the error is the same.
>>
> The constructor for array must be declared constexpr as well.
> The following works with clang 3.1, 3.2 and gcc 4.7.1, 4.7.2. I have no
> access to other C++11 compilers now. Could you try it?

The error is still the same.

./constexpr_test.cpp: In function ‘int main(int, char**)’:
./constexpr_test.cpp:20:21: in constexpr expansion of ‘arr.array<T,
n>::at<int, 5u>(10u)’
./constexpr_test.cpp:7:36: error: expression ‘<throw-expression>’ is
not a constant-expression
./constexpr_test.cpp:20:23: note: in template argument for type ‘int’
./constexpr_test.cpp:20:26: error: invalid type in declaration before ‘;’ token
./constexpr_test.cpp:21:14: error: request for member ‘get’ in ‘a’,
which is of non-class type ‘int’

The constructor doesn't make any difference, it's the at() method body
that causes the error.

The disappointing part is that the error message itself does not point
to the source of the problem and is misleading. The note before the
error mentions the method arguments but (a) it will not necessarily be
displayed by various IDEs and (b) it doesn't point out the problem
(i.e. that 10 > 5). If only it was possible to overload at() based on
constexpr qualification and use static_assert to display the
message...


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