public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56095] New: Crash casting function pointer as non-type template argument
@ 2013-01-24 5:23 spoo at zarbosoft dot com
2013-01-24 6:39 ` [Bug c++/56095] " spoo at zarbosoft dot com
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: spoo at zarbosoft dot com @ 2013-01-24 5:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
Bug #: 56095
Summary: Crash casting function pointer as non-type template
argument
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: spoo@zarbosoft.com
g++ crashes when trying to cast a function pointer to another function pointer
as a non-type template argument. I get a strange error in 4.6.3, and 4.7.2
segfaults.
Platform: Ubuntu 12.04.1 LTS
uname -a: Linux cerberus 3.2.0-35-generic #55-Ubuntu SMP Wed Dec 5 17:42:16 UTC
2012 x86_64 x86_64 x86_64 GNU/Linux
Code (c.cxx):
int *a(void) { return 0; }
typedef void (*IntermediarySignature)(void);
template <IntermediarySignature b> void z(void) {}
int main(int argc, char **argv)
{
z<(IntermediarySignature)a>();
z<reinterpret_cast<IntermediarySignature>(a)>();
return 0;
}
4.7 output:
> g++-4.7 -std=c++11 c.cxx
c.cxx: In function ‘int main(int, char**)’:
c.cxx:7:30: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.7/README.Bugs> for instructions.
Preprocessed source stored into /tmp/cc8vdZAa.out file, please attach this to
your bugreport.
If line 7 is commented out (the c-style cast), there's a segfault on line 8.
4.6 output:
> g++ -std=c++0x c.cxx
c.cxx: In function ‘int main(int, char**)’:
c.cxx:7:30: error: ‘(IntermediarySignature)a’ is not a valid template argument
for type ‘void (*)()’ because function ‘#‘nop_expr’ not supported by
dump_decl#<declaration error>’ has not external linkage
c.cxx:7:30: error: no matching function for call to ‘z()’
c.cxx:7:30: note: candidate is:
c.cxx:3:41: note: template<void (* b)()> void z()
c.cxx:8:48: error: ‘(IntermediarySignature)a’ is not a valid template argument
for type ‘void (*)()’ because function ‘#‘nop_expr’ not supported by
dump_decl#<declaration error>’ has not external linkage
c.cxx:8:48: error: no matching function for call to ‘z()’
c.cxx:8:48: note: candidate is:
c.cxx:3:41: note: template<void (* b)()> void z()
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
@ 2013-01-24 6:39 ` spoo at zarbosoft dot com
2013-01-24 11:56 ` daniel.kruegler at googlemail dot com
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: spoo at zarbosoft dot com @ 2013-01-24 6:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
--- Comment #1 from Rendaw <spoo at zarbosoft dot com> 2013-01-24 06:39:12 UTC ---
I tried one more case, casting before using the template:
Code (c.cxx):
int *a(void) { return 0; }
typedef void (*IntermediarySignature)(void);
template <IntermediarySignature b> void z(void) {}
int main(int argc, char **argv)
{
constexpr IntermediarySignature c = (IntermediarySignature)a;
z<c>();
return 0;
}
4.7 output:
> g++-4.7 -std=c++11 c.cxx
c.cxx: In function ‘int main(int, char**)’:
c.cxx:8:7: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.7/README.Bugs> for instructions.
Preprocessed source stored into /tmp/ccw2QOq9.out file, please attach this to
your bugreport.
4.6 output:
> g++ -std=c++0x c.cxx
c.cxx: In function ‘int main(int, char**)’:
c.cxx:8:7: error: ‘(IntermediarySignature)a’ is not a valid template argument
for type ‘void (*)()’ because function ‘#‘nop_expr’ not supported by
dump_decl#<declaration error>’ has not external linkage
c.cxx:8:7: error: no matching function for call to ‘z()’
c.cxx:8:7: note: candidate is:
c.cxx:3:41: note: template<void (* b)()> void z()
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
2013-01-24 6:39 ` [Bug c++/56095] " spoo at zarbosoft dot com
@ 2013-01-24 11:56 ` daniel.kruegler at googlemail dot com
2013-01-24 12:02 ` redi at gcc dot gnu.org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-01-24 11:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
Daniel Krügler <daniel.kruegler at googlemail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.kruegler at
| |googlemail dot com
--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-01-24 11:56:31 UTC ---
While I agree that the ICE needs to be fixed, let me add in here that any
conversion that requires the equivalent of a reinterpret_cast is not valid in a
constant expression in C++11. Furthermore, there are even more fundamental
restrictions on the form of the non-type template arguments as described in
[temp.arg.nontype] p1, which exclude *any* form of a cast expression at that
place. These rules also exclude the case that you tried in your second example
where you are attempting to use a constexpr variable.
The essential wording here is:
"a constant expression (5.19) that designates the address of [..] a function
with external or internal linkage, including function templates and function
template-ids [..], expressed (ignoring parentheses) as &id-expression, except
that the & may be omitted if the name refers to a function [..]"
Basically this means you can only directly name a function here such as
z<a>();
which of course won't work in your case because of the incompatible signature.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
2013-01-24 6:39 ` [Bug c++/56095] " spoo at zarbosoft dot com
2013-01-24 11:56 ` daniel.kruegler at googlemail dot com
@ 2013-01-24 12:02 ` redi at gcc dot gnu.org
2013-01-24 12:08 ` daniel.kruegler at googlemail dot com
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2013-01-24 12:02 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |ice-on-invalid-code
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-24 12:01:32 UTC ---
I cant reproduce the crash with any version
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
` (2 preceding siblings ...)
2013-01-24 12:02 ` redi at gcc dot gnu.org
@ 2013-01-24 12:08 ` daniel.kruegler at googlemail dot com
2013-01-24 12:11 ` [Bug c++/56095] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-01-24 12:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
--- Comment #4 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-01-24 12:07:25 UTC ---
(In reply to comment #3)
> I cant reproduce the crash with any version
Here is what I get with my mingw-64 gcc 4.8.0 20130120 (experimental):
"main.cpp||In function 'int main(int, char**)':|
main.cpp|7|internal compiler error: tree check: expected tree that contains
'decl minimal' structure, have 'nop_expr' in decl_linkage, at cp/tree.c:3527"
When I use
http://liveworkspace.org/code/47sr7W$0
I also get "source.cpp:7:33: internal compiler error: Segmentation fault"
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] [4.6/4.7/4.8 Regression] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
` (3 preceding siblings ...)
2013-01-24 12:08 ` daniel.kruegler at googlemail dot com
@ 2013-01-24 12:11 ` jakub at gcc dot gnu.org
2013-01-24 12:12 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-24 12:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
Summary|Crash casting function |[4.6/4.7/4.8 Regression]
|pointer as non-type |Crash casting function
|template argument |pointer as non-type
| |template argument
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-24 12:11:13 UTC ---
I can, with everything starting from
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166167
You need --enable-checking=yes compiler though.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] [4.6/4.7/4.8 Regression] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
` (4 preceding siblings ...)
2013-01-24 12:11 ` [Bug c++/56095] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
@ 2013-01-24 12:12 ` jakub at gcc dot gnu.org
2013-01-24 12:14 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-24 12:12 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
Target Milestone|--- |4.6.4
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] [4.6/4.7/4.8 Regression] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
` (5 preceding siblings ...)
2013-01-24 12:12 ` jakub at gcc dot gnu.org
@ 2013-01-24 12:14 ` redi at gcc dot gnu.org
2013-01-25 20:01 ` jason at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2013-01-24 12:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-01-24
Ever Confirmed|0 |1
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-24 12:13:56 UTC ---
Doh, sorry, copy'n'paste failure. I copied the test wrong.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] [4.6/4.7/4.8 Regression] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
` (6 preceding siblings ...)
2013-01-24 12:14 ` redi at gcc dot gnu.org
@ 2013-01-25 20:01 ` jason at gcc dot gnu.org
2013-01-25 20:05 ` [Bug c++/56095] [4.6/4.7 " jakub at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-25 20:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-25 20:01:35 UTC ---
Author: jason
Date: Fri Jan 25 20:01:29 2013
New Revision: 195474
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195474
Log:
PR c++/56095
* pt.c (convert_nontype_argument_function): Handle invalid input.
(convert_nontype_argument): Likewise.
Added:
trunk/gcc/testsuite/g++.dg/template/fn-ptr2.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/pt.c
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] [4.6/4.7 Regression] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
` (7 preceding siblings ...)
2013-01-25 20:01 ` jason at gcc dot gnu.org
@ 2013-01-25 20:05 ` jakub at gcc dot gnu.org
2013-01-25 20:20 ` jason at gcc dot gnu.org
2013-03-17 2:34 ` jason at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-25 20:05 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[4.6/4.7/4.8 Regression] |[4.6/4.7 Regression] Crash
|Crash casting function |casting function pointer as
|pointer as non-type |non-type template argument
|template argument |
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-25 20:04:59 UTC ---
Fixed on the trunk so far.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] [4.6/4.7 Regression] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
` (8 preceding siblings ...)
2013-01-25 20:05 ` [Bug c++/56095] [4.6/4.7 " jakub at gcc dot gnu.org
@ 2013-01-25 20:20 ` jason at gcc dot gnu.org
2013-03-17 2:34 ` jason at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-25 20:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|4.6.4 |4.8.0
--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-25 20:20:22 UTC ---
And we usually don't backport fixes for invalid code.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/56095] [4.6/4.7 Regression] Crash casting function pointer as non-type template argument
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
` (9 preceding siblings ...)
2013-01-25 20:20 ` jason at gcc dot gnu.org
@ 2013-03-17 2:34 ` jason at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-17 2:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56095
--- Comment #10 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-17 02:33:46 UTC ---
Author: jason
Date: Sun Mar 17 02:33:38 2013
New Revision: 196722
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196722
Log:
PR c++/56095
* class.c (resolve_address_of_overloaded_function): Accept a
reference to function for target_type.
(instantiate_type): Likewise.
* pt.c (convert_nontype_argument): Pass it to
convert_nontype_argument_function.
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/class.c
trunk/gcc/cp/pt.c
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-03-17 2:34 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-24 5:23 [Bug c++/56095] New: Crash casting function pointer as non-type template argument spoo at zarbosoft dot com
2013-01-24 6:39 ` [Bug c++/56095] " spoo at zarbosoft dot com
2013-01-24 11:56 ` daniel.kruegler at googlemail dot com
2013-01-24 12:02 ` redi at gcc dot gnu.org
2013-01-24 12:08 ` daniel.kruegler at googlemail dot com
2013-01-24 12:11 ` [Bug c++/56095] [4.6/4.7/4.8 Regression] " jakub at gcc dot gnu.org
2013-01-24 12:12 ` jakub at gcc dot gnu.org
2013-01-24 12:14 ` redi at gcc dot gnu.org
2013-01-25 20:01 ` jason at gcc dot gnu.org
2013-01-25 20:05 ` [Bug c++/56095] [4.6/4.7 " jakub at gcc dot gnu.org
2013-01-25 20:20 ` jason at gcc dot gnu.org
2013-03-17 2:34 ` jason 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).