public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12046] New: parse error in template function
@ 2003-08-24 17:44 gcc-bugzilla at gcc dot gnu dot org
2003-08-24 17:54 ` [Bug c++/12046] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2003-08-24 17:44 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12046
Summary: parse error in template function
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cspiel at freenet dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
Environment:
System: Linux hydra 2.4.21-ac4 #1 SMP Mon Jul 14 20:13:09 CEST 2003 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../configure --prefix=/usr --infodir=/usr/share/info
How-To-Repeat:
# 1 "compiler-bug.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "compiler-bug.cc"
template<class T> struct Traits {};
struct Traits<int>
{
static const bool b = true;
};
struct Traits<unsigned>
{
static const bool b = false;
};
# 31 "compiler-bug.cc"
template<bool b> struct C {};
struct C<true>
{
template<class T> inline static T f(T x) { return -x; }
};
struct C<false>
{
template<class T> inline static T f(T x) { return x; }
};
# 54 "compiler-bug.cc"
template<class T> T special_f(T x)
{
return C<Traits<int>::b>::f<T>(x);
}
template<class T> T any_f(T x)
{
return C<Traits<T>::b>::f<T>(x);
}
int force_instantiation(int i)
{
return special_f<int>(i) + any_f<int>(i);
}
$ g++ -v -Wall -c compiler-bug.cc
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3/specs
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --enable-threads
Thread model: posix
gcc version 3.3
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3/cc1plus -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=0 -D_GNU_SOURCE compiler-bug.cc -D__GNUG__=3 -quiet -dumpbase compiler-bug.cc -auxbase compiler-bug -Wall -version -o /tmp/ccU7FMbF.s
GNU C++ version 3.3 (i686-pc-linux-gnu)
compiled by GNU C version 3.3.
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32000
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/3.3
/usr/include/c++/3.3/i686-pc-linux-gnu
/usr/include/c++/3.3/backward
/usr/local/include
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3/include
/usr/i686-pc-linux-gnu/include
/usr/include
End of search list.
compiler-bug.cc: In function `T any_f(T)':
compiler-bug.cc:66: error: parse error before `>' token
------- Additional Comments From cspiel at freenet dot de 2003-08-24 17:43 -------
Fix:
This is a work around, not a fix: Replace compile-time function
selection via expression template with run-time selection via ternary
operator. (This is no very appealing from the optimization point of
view and even less appealing from the error/warning point of view,
because of spurious error messages, e.g. "comparison of signed with
unsigned" when the templated code would compile cleanly.)
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/12046] parse error in template function
2003-08-24 17:44 [Bug c++/12046] New: parse error in template function gcc-bugzilla at gcc dot gnu dot org
@ 2003-08-24 17:54 ` pinskia at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-24 17:54 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12046
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-08-24 17:54 -------
The code is invalid as the template C<Traits<T>::b>::f in any_f is depend on the template
argument T so you need to help the compiler to know that it is a template.
Here is the correct fix:
template<class T> T any_f(T x)
{
return C<Traits<T>::b>::template f<T>(x);
}
Also note you specifications of Traits are wrong, they should have template<> infront of the
structs, also the specifications of C is the same way.
Once these are fixed you can compile your code on the mainline of GCC.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-08-24 17:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-24 17:44 [Bug c++/12046] New: parse error in template function gcc-bugzilla at gcc dot gnu dot org
2003-08-24 17:54 ` [Bug c++/12046] " pinskia at gcc dot gnu dot 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).