This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/12046] New: parse error in template function


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.)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]