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++/59475] New: gcc with flag -O1 fails to find template specialization when there is default one.


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59475

            Bug ID: 59475
           Summary: gcc with flag -O1 fails to find template
                    specialization when there is default one.
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: akela1101 at gmail dot com

Different behaviour with -O1 and without.
In first case g++ doesn't see template instantiation in .cpp and uses default.
In second case it uses .cpp even without function declaration.

Tested on x86 gcc-4.8.2 and x64 gcc-4.7.2.

Example:
=== A.h ===

#ifndef A_H
#define A_H

template<typename T>
int foo(T) { return 10; }

struct A
{
    int x;
};

//template<>
//int foo(A t);

#endif // A_H

=== A.cpp ===

#include "A.h"

template<>
int foo(A t) { return t.x; }

=== main.cpp ===
#include "A.h"

int main()
{
    A a;
    a.x = 5;
    int b = 10;
    if( foo(a) == foo(b) ) return 1;
    return 0;
}

=======

Run script from attachment. Output must be:
$ ./run.sh 
Without flags
0
With -O1
1


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