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

           Summary: ?: ternary operator fails in certain contexts - link
                    error
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: adele.schmidtham...@yahoo.de


probably there is a relation to bug 48882

I do not attach the precompiled file (.ii), because it is too big.

#include<algorithm> // std::max  std::min
#include<iostream>

template<typename T>
const T& myMin(const T& a, const T& b) {
   if(a < b) return a;
   return b;
}
template<typename T>
const T& myMax(const T& a, const T& b) {
   if(a > b) return a;
   return b;
}

int main() {
   int a = 1000;
   int b = 2000;
   bool even = true;
   const int& (*fp)(const int&, const int&);
   fp = even ? myMax<int> : myMin<int>;   /* yields link error */
    std::cout << fp(a,b) << std::endl;
}

does not link. Output :

Es werden eingebaute Spezifikationen verwendet.
COLLECT_GCC=/home/me/programme/gcc47/bin/g++
COLLECT_LTO_WRAPPER=/home/me/programme/gcc47/libexec/gcc/i686-pc-linux-gnu/4.7.0/lto-wrapper
Ziel: i686-pc-linux-gnu
Konfiguriert mit: ./configure --prefix=/home/me/programme/gcc47
Thread-Modell: posix
gcc-Version 4.7.0 20110430 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-std=c++0x' '-Wall' '-save-temps' '-shared-libgcc'
'-mtune=generic' '-march=pentiumpro'
 /home/me/programme/gcc47/libexec/gcc/i686-pc-linux-gnu/4.7.0/cc1plus -E -quiet
-v -D_GNU_SOURCE bug2.cpp -mtune=generic -march=pentiumpro -std=c++0x -Wall
-fpch-preprocess -o bug2.ii
nicht vorhandenes Verzeichnis
»/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../i686-pc-linux-gnu/include«
wird ignoriert
#include "..." - Suche beginnt hier:
#include <...> - Suche beginnt hier:

/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../include/c++/4.7.0

/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../include/c++/4.7.0/i686-pc-linux-gnu

/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../include/c++/4.7.0/backward
 /home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/include
 /usr/local/include
 /home/me/programme/gcc47/include
 /home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/include-fixed
 /usr/include
Ende der Suchliste.
COLLECT_GCC_OPTIONS='-v' '-std=c++0x' '-Wall' '-save-temps' '-shared-libgcc'
'-mtune=generic' '-march=pentiumpro'
 /home/me/programme/gcc47/libexec/gcc/i686-pc-linux-gnu/4.7.0/cc1plus
-fpreprocessed bug2.ii -quiet -dumpbase bug2.cpp -mtune=generic
-march=pentiumpro -auxbase bug2 -Wall -std=c++0x -version -o bug2.s
GNU C++ (GCC) Version 4.7.0 20110430 (experimental) (i686-pc-linux-gnu)
    kompiliert von GNU-C-Version 4.7.0 20110430 (experimental), GMP-Version
5.0.1, MPFR-Version 3.0.0-p3, MPC-Version 0.8.2.
GGC-Heuristik: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C++ (GCC) Version 4.7.0 20110430 (experimental) (i686-pc-linux-gnu)
    kompiliert von GNU-C-Version 4.7.0 20110430 (experimental), GMP-Version
5.0.1, MPFR-Version 3.0.0-p3, MPC-Version 0.8.2.
GGC-Heuristik: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: c95befb475332395eb1695ad61c47f68
COLLECT_GCC_OPTIONS='-v' '-std=c++0x' '-Wall' '-save-temps' '-shared-libgcc'
'-mtune=generic' '-march=pentiumpro'
 as --32 -o bug2.o bug2.s
COMPILER_PATH=/home/me/programme/gcc47/libexec/gcc/i686-pc-linux-gnu/4.7.0/:/home/me/programme/gcc47/libexec/gcc/i686-pc-linux-gnu/4.7.0/:/home/me/programme/gcc47/libexec/gcc/i686-pc-linux-gnu/:/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/:/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/
LIBRARY_PATH=/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/:/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-std=c++0x' '-Wall' '-save-temps' '-shared-libgcc'
'-mtune=generic' '-march=pentiumpro'
 /home/me/programme/gcc47/libexec/gcc/i686-pc-linux-gnu/4.7.0/collect2
--eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o
/usr/lib/crti.o
/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/crtbegin.o
-L/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0
-L/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/../../.. bug2.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/home/me/programme/gcc47/lib/gcc/i686-pc-linux-gnu/4.7.0/crtend.o
/usr/lib/crtn.o
bug2.o: In function `main':
bug2.cpp:(.text+0x26): undefined reference to `int const& myMax<int>(int
const&, int const&)'
bug2.cpp:(.text+0x2d): undefined reference to `int const& myMin<int>(int
const&, int const&)'
collect2: ld gab 1 als Ende-Status zurück

Reply via email to