Bug 16617 - Fail to do access checking correctly for non-dependent qualified-id
Summary: Fail to do access checking correctly for non-dependent qualified-id
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: accepts-invalid
: 24118 33934 (view as bug list)
Depends on:
Blocks: 13495
  Show dependency treegraph
 
Reported: 2004-07-18 13:52 UTC by Kriang Lerdsuwanakij
Modified: 2021-04-22 17:45 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-04-22 05:12:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kriang Lerdsuwanakij 2004-07-18 13:52:32 UTC
This is a spin out of a problem mentioned in PR13092.
The following testcase shouldn't compile because only
fr<int> is friend of class D.  But we are accessing
protected members from fr<char>.  GCC 3.4, 3.5 fail
to diagnose it.  Earlier GCC don't handle this properly
(checking access while parsing the template fr<T> which
is too early.)  So it's not a regression.


// Two-phase name lookup for address of member:
// Protected member access

class B
{
  protected:
  int i;			// { dg-error "protected" }
};

template <class T> void fr ();

class D2 : public B
{
  friend void fr<int> ();
};

template<int B::*> struct X
{};

template <class T> void fr ()
{
  X<&B::i> x1;			// { dg-error "context" }
  X<&D2::i> x2;			// { dg-error "context" }
}

template void fr<char>();	// { dg-error "instantiated" }
Comment 1 Wolfgang Bangerth 2004-07-28 13:48:57 UTC
Confirmed. 
W. 
Comment 2 Kriang Lerdsuwanakij 2004-12-12 12:42:31 UTC
Got it.  The target for this fix is GCC 4.1.
Comment 3 Kriang Lerdsuwanakij 2005-01-12 10:50:37 UTC
May be fixed together with PR19311.
Comment 4 Kriang Lerdsuwanakij 2005-04-23 15:30:17 UTC
This is a stage 2 project.  Likely to be fixed in a month or two.
Comment 5 Kriang Lerdsuwanakij 2005-05-19 17:09:02 UTC
Patch using new approach for 4.1:
  http://gcc.gnu.org/ml/gcc-patches/2005-05/msg01992.html
(Note this is part 4 in a series, earlier parts are also required)
Comment 6 Kriang Lerdsuwanakij 2005-06-07 14:58:59 UTC
Patch withdrawn due to overlooking default function argument and default
template argument. No nice solution is found yet.
Comment 7 Andrew Pinski 2009-04-29 07:05:07 UTC
*** Bug 33934 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2009-04-29 07:05:41 UTC
*** Bug 24118 has been marked as a duplicate of this bug. ***
Comment 9 GCC Commits 2021-04-22 17:41:05 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:330cc29c06306ebf7bd3b2d37704cc69944923ff

commit r12-69-g330cc29c06306ebf7bd3b2d37704cc69944923ff
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Apr 22 13:32:40 2021 -0400

    c++: Add testcase for already fixed PR [PR16617]
    
    We correctly diagnose the invalid access since r11-1350.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/16617
            * g++.dg/template/access36.C: New test.
Comment 10 Patrick Palka 2021-04-22 17:45:28 UTC
Fixed for GCC 11 by the patch for PR41437.