public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66475] New: Access checking in templates circumvented with 'using' (C++11)
@ 2015-06-09 16:47 zerolo at gmail dot com
  2015-06-09 16:54 ` [Bug c++/66475] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zerolo at gmail dot com @ 2015-06-09 16:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66475

            Bug ID: 66475
           Summary: Access checking in templates circumvented with 'using'
                    (C++11)
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zerolo at gmail dot com
  Target Milestone: ---

Created attachment 35731
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35731&action=edit
repo that compiles with g++-4.9.2 -std=c++11

This is a variant of the various access checking problems when using templates,
but I don't think it's a duplicate of any of the existing ones in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59002 , as this one is only
triggered with the `using` directive in C++11 mode, but not when employing the
supposedly identical typedef.

Code that accesses a type that should be private compiles, even though it
shouldn't be able to. When either a) the using directive "using Base = Foo<T>"
is replaced by the equivalent typedef, or b) later no other type from Base is
publicized, then access is correctly prohibited and the example fails to
compile.

// g++-4.9.2 -std=c++11 t.cpp
template<class T>
struct Foo
{
  using type = T;
};

template<class T>
class Bar : public Foo<T>
{
  using Base = Foo<T>; // the combination of this and the public export of a
type from Base below, causes this example to compile even though it shouldn't
  // typedef Foo<T> Base; // when using typedef instead of using, it correctly
fails to compile
public:
  // without this public export, Base is correctly recognized as private, maybe
it erroneously make Base itself public?

  // whether written as 'typedef' or 'using' doesn't matter
  using type = typename Base::type;
};

Bar<int>::Base x; // shouldn't compile, Base is private

int main()
{
  return 0;
}


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

end of thread, other threads:[~2021-08-05  7:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-09 16:47 [Bug c++/66475] New: Access checking in templates circumvented with 'using' (C++11) zerolo at gmail dot com
2015-06-09 16:54 ` [Bug c++/66475] " redi at gcc dot gnu.org
2020-03-12 15:56 ` redi at gcc dot gnu.org
2021-07-27  8:46 ` pinskia at gcc dot gnu.org
2021-08-05  7:39 ` pinskia at gcc dot gnu.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).