public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/42292]  New: gcc should reject code violating the two-phase look-up rules (related to bug 42291)
@ 2009-12-05  0:02 wan at google dot com
  2009-12-05  0:06 ` [Bug c++/42292] fundamental type have an associated namespace? pinskia at gcc dot gnu dot org
  2009-12-05  0:10 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: wan at google dot com @ 2009-12-05  0:02 UTC (permalink / raw)
  To: gcc-bugs

The following code shouldn't compile; yet gcc accepts it:

template <typename T>
int Foo() {
 return Bar(T());
}

int x = Foo<bool>();  // This shouldn't compile.

int Bar(bool x) {
 return 0;
}

The problem is that when Foo<bool>() is instantiated, the compiler should
search for Bar() only at the template definition site, not at the point of
instantiation, since bool is not a class type and ADL doesn't apply.

Similarly, this shouldn't compile either, but gcc also accepts it:

template <typename T>
int Foo() {
 return Bar(T());
}

int Bar(bool x) {
 return 0;
}

int x = Foo<bool>();  // This shouldn't compile.

Note that both clang and Comeau reject the code correctly.

This is related to bug 42291 - I don't know if they are caused by exactly the
same thing though.


-- 
           Summary: gcc should reject code violating the two-phase look-up
                    rules (related to bug 42291)
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wan at google dot com


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


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

end of thread, other threads:[~2009-12-05  0:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-05  0:02 [Bug c++/42292] New: gcc should reject code violating the two-phase look-up rules (related to bug 42291) wan at google dot com
2009-12-05  0:06 ` [Bug c++/42292] fundamental type have an associated namespace? pinskia at gcc dot gnu dot org
2009-12-05  0:10 ` pinskia at gcc dot gnu dot org

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