public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102262] New: No reason given for constexpr function that uses non-constexpr destructor
@ 2021-09-09 16:47 redi at gcc dot gnu.org
2021-09-09 17:57 ` [Bug c++/102262] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-09 16:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102262
Bug ID: 102262
Summary: No reason given for constexpr function that uses
non-constexpr destructor
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
template<typename T>
struct foo
{
constexpr foo() { }
~foo() { }
};
template<typename T>
constexpr bool check()
{
T t;
return true;
}
static_assert( check<foo<int>>() );
The error doesn't tell you what's wrong:
ce.C:15:31: error: non-constant condition for static assertion
15 | static_assert( check<foo<int>>() );
| ~~~~~~~~~~~~~~~^~
ce.C:15:31: error: 'constexpr bool check() [with T = foo<int>]' called in a
constant expression
ce.C:9:16: note: 'constexpr bool check() [with T = foo<int>]' is not usable as
a 'constexpr' function because:
9 | constexpr bool check()
| ^~~~~
The problem is that the destructor is not constexpr.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102262] No reason given for constexpr function that uses non-constexpr destructor
2021-09-09 16:47 [Bug c++/102262] New: No reason given for constexpr function that uses non-constexpr destructor redi at gcc dot gnu.org
@ 2021-09-09 17:57 ` pinskia at gcc dot gnu.org
2021-09-09 20:57 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-09 17:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102262
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-09-09
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Interesting only MSVC provides the reason:
<source>(15): error C2131: expression did not evaluate to a constant
<source>(11): note: failure was caused by call of undefined function or one not
declared 'constexpr'
<source>(11): note: see usage of 'foo<int>::~foo'
clang does not either:
<source>:15:16: error: static_assert expression is not an integral constant
expression
static_assert( check<foo<int>>() );
^~~~~~~~~~~~~~~~~
<source>:11:5: note: non-literal type 'foo<int>' cannot be used in a constant
expression
T t;
^
<source>:15:16: note: in call to 'check()'
static_assert( check<foo<int>>() );
^
Nor EDG (ICC):
<source>(15): error: expression must have a constant value
static_assert( check<foo<int>>() );
^
<source>(15): note: cannot call non-constexpr function "check<T>() [with
T=foo<int>]" (declared at line 9)
static_assert( check<foo<int>>() );
^
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102262] No reason given for constexpr function that uses non-constexpr destructor
2021-09-09 16:47 [Bug c++/102262] New: No reason given for constexpr function that uses non-constexpr destructor redi at gcc dot gnu.org
2021-09-09 17:57 ` [Bug c++/102262] " pinskia at gcc dot gnu.org
@ 2021-09-09 20:57 ` jakub at gcc dot gnu.org
2021-09-09 21:04 ` jakub at gcc dot gnu.org
2021-11-08 13:33 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-09 20:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102262
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Simpler testcase, the class doesn't need to be a template, but check does:
struct S
{
constexpr S () { }
~S () { }
};
template <typename T>
constexpr bool check ()
{
T t;
return true;
}
constexpr bool a = check<S> ();
constexpr bool check2 ()
{
S s;
return true;
}
constexpr bool b = check2 ();
because check2 is diagnosed properly:
pr102262.C: In function ‘constexpr bool check2()’:
pr102262.C:18:5: error: variable ‘s’ of non-literal type ‘S’ in ‘constexpr’
function
18 | S s;
| ^
pr102262.C:1:8: note: ‘S’ is not literal because:
1 | struct S
| ^
pr102262.C:1:8: note: ‘S’ does not have ‘constexpr’ destructor
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102262] No reason given for constexpr function that uses non-constexpr destructor
2021-09-09 16:47 [Bug c++/102262] New: No reason given for constexpr function that uses non-constexpr destructor redi at gcc dot gnu.org
2021-09-09 17:57 ` [Bug c++/102262] " pinskia at gcc dot gnu.org
2021-09-09 20:57 ` jakub at gcc dot gnu.org
@ 2021-09-09 21:04 ` jakub at gcc dot gnu.org
2021-11-08 13:33 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-09 21:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102262
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Seems ensure_literal_type_for_constexpr_object doesn't emit any errors in
instatiations of constexpr functions:
if (CLASS_TYPE_P (stype) && !COMPLETE_TYPE_P (complete_type (stype)))
/* Don't complain here, we'll complain about incompleteness
when we try to initialize the variable. */;
else if (!literal_type_p (type))
{
if (DECL_DECLARED_CONSTEXPR_P (decl))
...
else
{
if (!is_instantiation_of_constexpr (current_function_decl))
{
auto_diagnostic_group d;
error_at (DECL_SOURCE_LOCATION (decl),
"variable %qD of non-literal type %qT in "
"%<constexpr%> function", decl, type);
explain_non_literal_class (type);
decl = error_mark_node;
}
cp_function_chain->invalid_constexpr = true;
}
When parsing, this isn't reached because of && !processing_template_decl, and
when it is instantiated, is_instantiation_of_constexpr (current_function_decl)
is true and so it doesn't emit the error, but just sets invalid_constexpr.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/102262] No reason given for constexpr function that uses non-constexpr destructor
2021-09-09 16:47 [Bug c++/102262] New: No reason given for constexpr function that uses non-constexpr destructor redi at gcc dot gnu.org
` (2 preceding siblings ...)
2021-09-09 21:04 ` jakub at gcc dot gnu.org
@ 2021-11-08 13:33 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-08 13:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102262
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Another variation:
template<typename _Tp>
struct vector
{
struct _Temp_value
{
constexpr
_Temp_value()
{
}
#ifndef ICE
constexpr
~_Temp_value()
{ }
#endif
union _Storage
{
constexpr _Storage() : _M_byte() { }
~_Storage() { }
unsigned char _M_byte;
};
_Storage _M_storage;
};
constexpr void
insert()
{
_Temp_value v;
}
};
constexpr bool
test()
{
vector<int> v;
v.insert();
return true;
}
static_assert( test() );
With -std=c++20 this prints:
ce.C:43:20: error: non-constant condition for static assertion
43 | static_assert( test() );
| ~~~~^~
ce.C:43:20: in 'constexpr' expansion of 'test()'
ce.C:38:11: error: 'constexpr void vector<_Tp>::insert() [with _Tp = int]'
called in a constant expression
38 | v.insert();
| ~~~~~~~~^~
ce.C:28:5: note: 'constexpr void vector<_Tp>::insert() [with _Tp = int]' is not
usable as a 'constexpr' function because:
28 | insert()
| ^~~~~~
But with -std=c++20 -DICE it ICEs:
ce.C:43:20: error: non-constant condition for static assertion
43 | static_assert( test() );
| ~~~~^~
ce.C:43:20: in ‘constexpr’ expansion of ‘test()’
ce.C:38:11: error: ‘constexpr void vector<_Tp>::insert() [with _Tp = int]’
called in a constant expression
38 | v.insert();
| ~~~~~~~~^~
ce.C:28:5: note: ‘constexpr void vector<_Tp>::insert() [with _Tp = int]’ is not
usable as a ‘constexpr’ function because:
28 | insert()
| ^~~~~~
ce.C:31:5: error: call to non-‘constexpr’ function
‘vector<int>::_Temp_value::~_Temp_value()’
31 | }
| ^
ce.C:4:14: note: ‘vector<int>::_Temp_value::~_Temp_value()’ is not usable as a
‘constexpr’ function because:
4 | struct _Temp_value
| ^~~~~~~~~~~
ce.C:4:14: internal compiler error: in synthesized_method_walk, at
cp/method.c:2531
0x6b9809 synthesized_method_walk
/home/jwakely/src/gcc/gcc/gcc/cp/method.c:2531
0xa3f243 explain_implicit_non_constexpr(tree_node*)
/home/jwakely/src/gcc/gcc/gcc/cp/method.c:2887
0x977a17 explain_invalid_constexpr_fn(tree_node*)
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:976
0x9767f7 potential_constant_expression_1
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:8220
0x9758a1 potential_constant_expression_1
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:8445
0x976d38 potential_constant_expression_1(tree_node*, bool, bool, bool, int)
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:9126
0x976d38 require_potential_rvalue_constant_expression(tree_node*)
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:9160
0x977638 explain_invalid_constexpr_fn(tree_node*)
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:984
0x96d8aa cxx_eval_call_expression
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:2629
0x96f406 cxx_eval_constant_expression
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:6344
0x96f362 cxx_eval_constant_expression
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:6674
0x96f1c8 cxx_eval_constant_expression
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:6542
0x97054a cxx_eval_statement_list
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:5881
0x97054a cxx_eval_constant_expression
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:7013
0x96f3e8 cxx_eval_constant_expression
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:7048
0x96cae0 cxx_eval_call_expression
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:2789
0x96f406 cxx_eval_constant_expression
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:6344
0x973296 cxx_eval_outermost_constant_expr
/home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:7409
0xb5bb39 finish_static_assert(tree_node*, tree_node*, unsigned int, bool, bool)
/home/jwakely/src/gcc/gcc/gcc/cp/semantics.c:10457
0xaa1b5d cp_parser_static_assert
/home/jwakely/src/gcc/gcc/gcc/cp/parser.c:16166
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-08 13:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09 16:47 [Bug c++/102262] New: No reason given for constexpr function that uses non-constexpr destructor redi at gcc dot gnu.org
2021-09-09 17:57 ` [Bug c++/102262] " pinskia at gcc dot gnu.org
2021-09-09 20:57 ` jakub at gcc dot gnu.org
2021-09-09 21:04 ` jakub at gcc dot gnu.org
2021-11-08 13:33 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).