public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48882] New: ?: ternary operator fails in certain contexts - compile error
@ 2011-05-05 11:42 adele.schmidthammer at yahoo dot de
  2011-05-05 11:55 ` [Bug c++/48882] " adele.schmidthammer at yahoo dot de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: adele.schmidthammer at yahoo dot de @ 2011-05-05 11:42 UTC (permalink / raw)
  To: gcc-bugs

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

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


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

int main() {
   int a = 1000;
   int b = 2000;
   bool even = true;
   const int& (*fp)(const int&, const int&);    
   fp = even ? std::max<int> : std::min<int>;  /* does not compile! */
   std::cout << fp(a,b) << std::endl;
}

Error message: insufficient contextual information to determine type

however
     if(even) fp = std::max<int>;
     else     fp = std::min<int>;

works as expected:

Output of compilation:
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 bug1.cpp -mtune=generic -march=pentiumpro -std=c++0x -Wall
-fpch-preprocess -o bug1.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 bug1.ii -quiet -dumpbase bug1.cpp -mtune=generic
-march=pentiumpro -auxbase bug1 -Wall -std=c++0x -version -o bug1.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
bug1.cpp: In Funktion »int main()«:
bug1.cpp:19:38: Fehler: insufficient contextual information to determine type
bug1.cpp:19:38: Fehler: insufficient contextual information to determine type


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/48882] ?: ternary operator fails in certain contexts - compile error
  2011-05-05 11:42 [Bug c++/48882] New: ?: ternary operator fails in certain contexts - compile error adele.schmidthammer at yahoo dot de
@ 2011-05-05 11:55 ` adele.schmidthammer at yahoo dot de
  2011-07-04 22:32 ` [Bug libstdc++/48882] " jason at gcc dot gnu.org
  2011-07-07  9:35 ` [Bug libstdc++/48882] [C++0x] " paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: adele.schmidthammer at yahoo dot de @ 2011-05-05 11:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Adele Schmidt <adele.schmidthammer at yahoo dot de> 2011-05-05 11:37:33 UTC ---
no attachment, because precompiled file (extension .ii) was too big


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/48882] ?: ternary operator fails in certain contexts - compile error
  2011-05-05 11:42 [Bug c++/48882] New: ?: ternary operator fails in certain contexts - compile error adele.schmidthammer at yahoo dot de
  2011-05-05 11:55 ` [Bug c++/48882] " adele.schmidthammer at yahoo dot de
@ 2011-07-04 22:32 ` jason at gcc dot gnu.org
  2011-07-07  9:35 ` [Bug libstdc++/48882] [C++0x] " paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jason at gcc dot gnu.org @ 2011-07-04 22:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
          Component|c++                         |libstdc++

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2011-07-04 22:30:42 UTC ---
In C++0x max<int> no longer designates a single template specialization, as now
there are initializer_list overloads as well:

template<class T> const T& max(const T& a, const T& b);
template<class T> T max(initializer_list<T> t);

And likewise for min.  So the type of the ?: expression is unknown.  When you
rewrite it as if/else you provide a type to resolve to, so it works.

This is not a compiler bug.  Leaving as unconfirmed and changing category to
libstdc++ in case the library folks think this is an issue worth raising with
the committee.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libstdc++/48882] [C++0x] ?: ternary operator fails in certain contexts - compile error
  2011-05-05 11:42 [Bug c++/48882] New: ?: ternary operator fails in certain contexts - compile error adele.schmidthammer at yahoo dot de
  2011-05-05 11:55 ` [Bug c++/48882] " adele.schmidthammer at yahoo dot de
  2011-07-04 22:32 ` [Bug libstdc++/48882] " jason at gcc dot gnu.org
@ 2011-07-07  9:35 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-07-07  9:35 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID
            Summary|?: ternary operator fails   |[C++0x] ?: ternary operator
                   |in certain contexts -       |fails in certain contexts -
                   |compile error               |compile error

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-07-07 09:34:55 UTC ---
I think we can close this.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-07-07  9:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-05 11:42 [Bug c++/48882] New: ?: ternary operator fails in certain contexts - compile error adele.schmidthammer at yahoo dot de
2011-05-05 11:55 ` [Bug c++/48882] " adele.schmidthammer at yahoo dot de
2011-07-04 22:32 ` [Bug libstdc++/48882] " jason at gcc dot gnu.org
2011-07-07  9:35 ` [Bug libstdc++/48882] [C++0x] " paolo.carlini at oracle dot com

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