aboutsummaryrefslogtreecommitdiff
path: root/test/SemaCXX/access.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-04-29 10:13:55 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-04-29 10:13:55 +0000
commitcad7e43c5aba88bf6affc155b02d8609485db41b (patch)
tree806a3a53cc7280fb65f9e9d3ef383d7057073c04 /test/SemaCXX/access.cpp
parentfed844d8676db8daece6144340284b09f901323d (diff)
Implement DR580: access checks for template parameters of a class template are
performed within the context of that class template. Patch by Ismail Pazarbasi! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180707 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/access.cpp')
-rw-r--r--test/SemaCXX/access.cpp76
1 files changed, 75 insertions, 1 deletions
diff --git a/test/SemaCXX/access.cpp b/test/SemaCXX/access.cpp
index 18ad301b5f..50f2eff87b 100644
--- a/test/SemaCXX/access.cpp
+++ b/test/SemaCXX/access.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
class C {
struct S; // expected-note {{previously declared 'private' here}}
@@ -32,3 +32,77 @@ namespace test1 {
class X {};
};
}
+
+// PR15209
+namespace PR15209 {
+ namespace alias_templates {
+ template<typename T1, typename T2> struct U { };
+ template<typename T1> using W = U<T1, float>;
+
+ class A {
+ typedef int I;
+ static constexpr I x = 0; // expected-note {{implicitly declared private here}}
+ static constexpr I y = 42; // expected-note {{implicitly declared private here}}
+ friend W<int>;
+ };
+
+ template<typename T1>
+ struct U<T1, float> {
+ int v_;
+ // the following will trigger for U<float, float> instantiation, via W<float>
+ U() : v_(A::x) { } // expected-error {{'x' is a private member of 'PR15209::alias_templates::A'}}
+ };
+
+ template<typename T1>
+ struct U<T1, int> {
+ int v_;
+ U() : v_(A::y) { } // expected-error {{'y' is a private member of 'PR15209::alias_templates::A'}}
+ };
+
+ template struct U<int, int>; // expected-note {{in instantiation of member function 'PR15209::alias_templates::U<int, int>::U' requested here}}
+
+ void f()
+ {
+ W<int>();
+ // we should issue diagnostics for the following
+ W<float>(); // expected-note {{in instantiation of member function 'PR15209::alias_templates::U<float, float>::U' requested here}}
+ }
+ }
+
+ namespace templates {
+ class A {
+ typedef int I; // expected-note {{implicitly declared private here}}
+ static constexpr I x = 0; // expected-note {{implicitly declared private here}}
+
+ template<int> friend struct B;
+ template<int> struct C;
+ template<template<int> class T> friend struct TT;
+ template<typename T> friend void funct(T);
+ };
+ template<A::I> struct B { };
+
+ template<A::I> struct A::C { };
+
+ template<template<A::I> class T> struct TT {
+ T<A::x> t;
+ };
+
+ template struct TT<B>;
+ template<A::I> struct D { }; // expected-error {{'I' is a private member of 'PR15209::templates::A'}}
+ template struct TT<D>;
+
+ // function template case
+ template<typename T>
+ void funct(T)
+ {
+ (void)A::x;
+ }
+
+ template void funct<int>(int);
+
+ void f()
+ {
+ (void)A::x; // expected-error {{'x' is a private member of 'PR15209::templates::A'}}
+ }
+ }
+}