[Bug c++/70377] New: "unexpected AST" and "confused by earlier errors, bailing out" from throw in simple constexpr fn
TonyELewis at hotmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Mar 23 14:50:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70377
Bug ID: 70377
Summary: "unexpected AST" and "confused by earlier errors,
bailing out" from throw in simple constexpr fn
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: TonyELewis at hotmail dot com
Target Milestone: ---
Compiling this code:
#include <array>
#include <cstddef>
#include <exception>
template <std::size_t N>
constexpr size_t simple_find(const std::array<int, N> &arg_array,
const int &arg_value
) {
for (size_t ctr = 0; ctr != N; ++ctr) {
if ( arg_array[ ctr ] == arg_value ) {
return ctr;
}
}
throw std::out_of_range( "" );
}
static constexpr std::array<int, 3> some_ints { { 10, 11 } };
static_assert( simple_find( some_ints, 10 ) == static_cast<size_t>( 0 ), "" );
static_assert( simple_find( some_ints, 11 ) == static_cast<size_t>( 1 ), "" );
int main() { }
...under -std=c++14 gives:
a.cpp:19:1: error: non-constant condition for static assertion
static_assert( simple_find( some_ints, 10 ) == static_cast<size_t>( 0 ), "" );
^
a.cpp:19:27: error: ‘constexpr size_t simple_find(const std::array<int, N>&,
const int&) [with long unsigned int N = 3ul; size_t = long unsigned int]’
called in a constant expression
static_assert( simple_find( some_ints, 10 ) == static_cast<size_t>( 0 ), "" );
^
a.cpp:6:18: note: ‘constexpr size_t simple_find(const std::array<int, N>&,
const int&) [with long unsigned int N = 3ul; size_t = long unsigned int]’ is
not usable as a constexpr function because:
constexpr size_t simple_find(const std::array<int, N> &arg_array,
^
a.cpp:6:18: sorry, unimplemented: unexpected AST of kind loop_expr
a.cpp:6: confused by earlier errors, bailing out
I think the code is valid C++14. Even if not, I doubt you want the errors seen
above.
The code compiles cleanly if the throw statement is replaced with 'return 0;'.
I'm seeing this issue on g++ (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010. I've also
tried it on http://melpon.org/wandbox and I think the issue is still there on a
recent 6.0.0 HEAD.
Thanks very much.
More information about the Gcc-bugs
mailing list