Discussion:
[C++ PAtch] More C++11 and C++14 constexpr work
Paolo Carlini
2014-10-08 19:47:38 UTC
Permalink
Hi,

the below tries to make progress on some relatively easy issues I
noticed while working on c++/55250. At least:
1- We rejected using declarations and using directives in constructors.
2- In C++14 mode we rejected compound-statements both in constructors
and elsewhere (and in C++11 we provided both the pedwarn and then an
hard error)
3- In C++14 mode we rejected local variables in constructors.

The patch itself uses quite straightforward strategies:
check_constexpr_ctor_body is extended via the new
check_constexpr_ctor_body_1; recursion on BIND_EXPRs takes care of
compound-statements; the parser is tweaked to suppress the
"compound-statement in constexpr function" pedwarn in C++14 mode.

Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
Jason Merrill
2014-10-09 13:31:31 UTC
Permalink
(check_constexpr_ctor_body): Use it; add bool parameter.
This function seems to only be called in one place; why add the parameter?

Jason
Paolo Carlini
2014-10-09 13:49:17 UTC
Permalink
Hi,
Post by Jason Merrill
(check_constexpr_ctor_body): Use it; add bool parameter.
This function seems to only be called in one place; why add the parameter?
Is also called recursively by check_constexpr_ctor_body_1 and without
the complain boolean we end up printing the error message twice.

Paolo.
Paolo Carlini
2014-10-09 13:56:46 UTC
Permalink
.. a simple example in C++11 would be:

struct S
{
constexpr S() { { struct T { }; } }
};

Paolo.
Jason Merrill
2014-10-09 14:18:12 UTC
Permalink
Post by Paolo Carlini
Hi,
Post by Jason Merrill
(check_constexpr_ctor_body): Use it; add bool parameter.
This function seems to only be called in one place; why add the parameter?
Is also called recursively by check_constexpr_ctor_body_1 and without
the complain boolean we end up printing the error message twice.
Ah, guess I overlooked that. OK.

Jason
Paolo Carlini
2014-10-09 15:15:43 UTC
Permalink
Hi,
Post by Jason Merrill
Post by Paolo Carlini
Hi,
Post by Jason Merrill
(check_constexpr_ctor_body): Use it; add bool parameter.
This function seems to only be called in one place; why add the parameter?
Is also called recursively by check_constexpr_ctor_body_1 and without
the complain boolean we end up printing the error message twice.
Ah, guess I overlooked that. OK.
Thanks, I'm going to commit the patch.

I noticed today that given the actual C++11 the error messages we provide:

"constexpr constructor does not have empty body"

and:

"body of constexpr function ‘XXX’ not a return-statement"

are rather outdated and misleading. In principle we should probably also
provide more fine grained error messages, but if you have suggestions
for less misleading catch all, I volunteer to do the change and adjust
the testcases...

Also, I have been thinking that it would probably make sense to move
constexpr-related code to a separate cp/constexpr.c: what do you think?
Functions with *constexpr* in the name, the various cxx_eval_* and the
various potential_constant_* would qualify, I think.

Paolo.

Loading...