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]

pending/7774: C++ Template partial specialization broken with functiontypes


>Number:         7774
>Category:       pending
>Synopsis:       C++ Template partial specialization broken with function types
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 30 08:46:02 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jaakko Jarvi
>Release:        3.2
>Organization:
>Environment:
System: SunOS ford.osl.iu.edu 5.8 Generic_108528-15 sun4u sparc SUNW,Sun-Blade-100
Architecture: sun4

	
host: sparc-sun-solaris2.8
build: sparc-sun-solaris2.8
target: sparc-sun-solaris2.8
configured with: ../dist/configure --prefix=/l/gcc320 --enable-language=c,c++,f77,java
>Description:
Suppose a primary template 

  template <class T> class A;

and a sepcialization:

  template <class T> class A<volatile T>;

When instantiated with a plain function type (that is, not a pointer or
reference to function), the compiler picks the specialization for volatile.
(It gives warnings that volatile qualifiers are ignored).

>How-To-Repeat:

This program demonstrates the error:

#include <iostream>

template <class T> class A { 
public:
  static void foo () { std::cout << "Not volatile"; }
};

template <class T> class A<volatile T> {
public:
  static void foo () { std::cout << "Volatile"; }
};

template <class T>
void x(T& t) {
  A<T>::foo();
  // T here should be a plain function type int()() (not a pointer, not a ref)

  // The compiler (3.20) picks the specializatoin for A<volatile T> ???
}

int bar() {};

int main() {
  x(bar);
};

// -----------------------

This the output from the compiler:

/l/gcc320/bin/g++ -I/u/jajarvi/boost testi.cpp
testi.cpp: In instantiation of `A<int ()()>':
testi.cpp:15:   instantiated from `void x(T&) [with T = int ()()]'
testi.cpp:24:   instantiated from here
testi.cpp:8: warning: ignoring `volatile' qualifiers on `int ()()'
testi.cpp:8: warning: ignoring `volatile' qualifiers on `int ()()'

And when the program is run, it outputs "Volatile".

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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