Boost logo

Boost :

Subject: Re: [boost] Boost.Exception and constexpr
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-01-10 14:31:30

Le 10/01/13 20:12, Andrey Semashev a écrit :
> 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.
Yes it does. The error you get here is the one you must obtain when the
exception is throw during compile time.
> 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...
The error message is a QOI. Here it is the error with clang 3.1/3.2

../example/test_so.cpp:20:12: error: non-type template argument is not a
constant expression
     check< > a;
../example/test_so.cpp:7:30: note: subexpression not valid in a constant
         return i < n ? T() : throw 0;
../example/test_so.cpp:20:12: note: in call to '10->at()'
     check< > a;


Boost list run by bdawes at, gregod at, cpdaniel at, john at