public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/49399] [C++0x] substitution failure error
Date: Tue, 14 Jun 2011 12:11:00 -0000	[thread overview]
Message-ID: <bug-49399-4-SnMmsTqT1a@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-49399-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 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 <typename T>
int
broken_fun(int, typename T::value_type* = 0);

template <typename T>
char
broken_fun(...);

int main(int argc, char* argv[])
{

  return sizeof(broken_fun<broken>(5));
}


  parent reply	other threads:[~2011-06-14 12:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-14  7:12 [Bug c++/49399] New: " jarrydb at cse dot unsw.edu.au
2011-06-14  8:15 ` [Bug c++/49399] " redi at gcc dot gnu.org
2011-06-14 11:53 ` jarrydb at cse dot unsw.edu.au
2011-06-14 12:11 ` redi at gcc dot gnu.org [this message]
2011-06-14 12:22 ` jarrydb at cse dot unsw.edu.au
2011-06-14 12:28 ` redi at gcc dot gnu.org
2011-06-14 12:31 ` redi at gcc dot gnu.org
2011-06-14 12:34 ` jarrydb at cse dot unsw.edu.au
2011-06-14 12:35 ` jarrydb at cse dot unsw.edu.au
2011-06-14 12:41 ` redi at gcc dot gnu.org
2011-06-15 16:47 ` jason at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-49399-4-SnMmsTqT1a@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).