public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102637] New: "Error: ‘reinterpret_cast’ is not a constant expression" when no reinterpret_cast is involved
@ 2021-10-07 11:42 officesamurai at gmail dot com
2022-02-12 22:05 ` [Bug c++/102637] " pinskia at gcc dot gnu.org
2023-11-09 19:54 ` ppalka at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: officesamurai at gmail dot com @ 2021-10-07 11:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102637
Bug ID: 102637
Summary: "Error: ‘reinterpret_cast’ is not a constant
expression" when no reinterpret_cast is involved
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: officesamurai at gmail dot com
Target Milestone: ---
Here I obtain a function pointer to the same member function two times, through
the base and through the derived class. Then I try to compare the pointers in a
constexpr context and it fails with the error "‘reinterpret_cast’ is not a
constant expression". The same happens when I try to static_cast each pointer
to the opposite type.
gcc_constexpr_funcptr_issue.cpp:
===
struct B1
{
void foo(int) {}
};
struct B2
{
void foo(bool) {}
};
struct D: B1
#ifndef ONE_BASE
, B2
#endif
{
using B1::foo;
#ifndef ONE_BASE
using B2::foo;
#endif
};
template <typename Class, typename Param>
constexpr auto select(void (Class::*func)(Param))
{
return func;
}
int main()
{
constexpr auto bFunc = select<B1, int>(&B1::foo);
constexpr auto dFunc = select<D, int>(&D::foo);
static_assert(bFunc == dFunc, "");
constexpr auto bFuncCastToDFunc = static_cast<void (D::*)(int)>(bFunc);
constexpr auto dFuncCastToBFunc = static_cast<void (B1::*)(int)>(dFunc);
}
===
Compiler invocation:
===
$ g++-11.2.0 -c gcc_constexpr_funcptr_issue.cpp
gcc_constexpr_funcptr_issue.cpp: In function ‘int main()’:
gcc_constexpr_funcptr_issue.cpp:33:25: error: non-constant condition for static
assertion
33 | static_assert(bFunc == dFunc, "");
| ~~~~~~^~~~~~~~
gcc_constexpr_funcptr_issue.cpp:33:28: error: ‘reinterpret_cast’ is not a
constant expression
33 | static_assert(bFunc == dFunc, "");
| ^~~~~
gcc_constexpr_funcptr_issue.cpp:35:39: error: ‘reinterpret_cast’ is not a
constant expression
35 | constexpr auto bFuncCastToDFunc = static_cast<void
(D::*)(int)>(bFunc);
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc_constexpr_funcptr_issue.cpp:36:39: error: ‘reinterpret_cast’ is not a
constant expression
36 | constexpr auto dFuncCastToBFunc = static_cast<void
(B1::*)(int)>(dFunc);
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
===
Additionally, if D has only one base, the call select<D, int>(&D::foo) also
fails:
---
$ g++-11.2.0 -DONE_BASE -c gcc_constexpr_funcptr_issue.cpp
gcc_constexpr_funcptr_issue.cpp: In function ‘int main()’:
gcc_constexpr_funcptr_issue.cpp:31:42: error: ‘reinterpret_cast’ is not a
constant expression
31 | constexpr auto dFunc = select<D, int>(&D::foo);
| ~~~~~~~~~~~~~~^~~~~~~~~
<skipped>
===
Finally, even if I replace the definitions of bFunc and dFunc with
constexpr auto bFunc = &B1::foo;
constexpr auto dFunc = &D::foo;
and use -DONE_BASE, one of the casts still fails:
===
$ g++-11.2.0 -DONE_BASE -c gcc_constexpr_funcptr_issue.cpp
gcc_constexpr_funcptr_issue.cpp: In function ‘int main()’:
gcc_constexpr_funcptr_issue.cpp:35:39: error: ‘reinterpret_cast’ is not a
constant expression
35 | constexpr auto bFuncCastToDFunc = static_cast<void
(D::*)(int)>(bFunc);
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
===
Compiler info:
===
$ g++-11.2.0 -v
Using built-in specs.
COLLECT_GCC=g++-11.2.0
COLLECT_LTO_WRAPPER=/home/brd/soft/gcc-11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/home/brd/soft/gcc-11.2.0
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
===
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/102637] "Error: ‘reinterpret_cast’ is not a constant expression" when no reinterpret_cast is involved
2021-10-07 11:42 [Bug c++/102637] New: "Error: ‘reinterpret_cast’ is not a constant expression" when no reinterpret_cast is involved officesamurai at gmail dot com
@ 2022-02-12 22:05 ` pinskia at gcc dot gnu.org
2023-11-09 19:54 ` ppalka at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-12 22:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102637
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |4.6.4, 4.7.1, 4.8.1, 4.9.0,
| |5.1.0, 6.1.0
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/102637] "Error: ‘reinterpret_cast’ is not a constant expression" when no reinterpret_cast is involved
2021-10-07 11:42 [Bug c++/102637] New: "Error: ‘reinterpret_cast’ is not a constant expression" when no reinterpret_cast is involved officesamurai at gmail dot com
2022-02-12 22:05 ` [Bug c++/102637] " pinskia at gcc dot gnu.org
@ 2023-11-09 19:54 ` ppalka at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-11-09 19:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102637
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |ppalka at gcc dot gnu.org
Resolution|--- |DUPLICATE
See Also|https://gcc.gnu.org/bugzill |
|a/show_bug.cgi?id=105996 |
--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
looks like this is pretty much a dup of PR105996, which has been fixed for
10.5/11.5/12.3/13
*** This bug has been marked as a duplicate of bug 105996 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-09 19:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-07 11:42 [Bug c++/102637] New: "Error: ‘reinterpret_cast’ is not a constant expression" when no reinterpret_cast is involved officesamurai at gmail dot com
2022-02-12 22:05 ` [Bug c++/102637] " pinskia at gcc dot gnu.org
2023-11-09 19:54 ` ppalka 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).