From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20310 invoked by alias); 14 Jun 2011 12:11:48 -0000 Received: (qmail 20293 invoked by uid 22791); 14 Jun 2011 12:11:40 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Jun 2011 12:11:26 +0000 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/49399] [C++0x] substitution failure error X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Tue, 14 Jun 2011 12:11:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg01175.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49399 --- Comment #3 from Jonathan Wakely 2011-06-14 12:11:05 UTC --- The program should not compile. In C++03 it should fail to compile because it accesses a private member. SFINAE does not take access control into account in C++03, so that is an error. G++ fails to reject the program because access checking in templates is buggy. There was a last minute change in the C++0x FDIS to make SFINAE consider access control. The previous draft (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf) says in section 14.8.2 [temp.deduct] p8 "Access checking is not done as part of the substitution process. Consequently, when deduction succeeds, an access error could still result when the function is instantiated." That was changed in the FDIS, so accessing the private member should cause deduction to fail, so there is no broken_fun and the call to it in main should fail. G++ 4.7 doesn't implement that change yet, so rejects the program for the wrong reason. If you had a second, less specific, overload of broken_fun then the program would still be invalid in C++03 but should be well-formed in C++0x. G++ doesn't accept it because access checking is not done as part of the substitution process yet. e.g. this is valid C++0x struct broken { private: typedef int value_type; }; template int broken_fun(int, typename T::value_type* = 0); template char broken_fun(...); int main(int argc, char* argv[]) { return sizeof(broken_fun(5)); }