File: warn-base-type-qualifiers.cpp

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,388 kB
  • sloc: cpp: 7,438,767; ansic: 1,393,871; asm: 1,012,926; python: 241,728; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (35 lines) | stat: -rw-r--r-- 1,621 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// RUN: %clang_cc1 %s -std=c++11 -Wignored-qualifiers -verify

template <typename T> struct add_const {
  using type = const T;
};
template <typename T> using add_const_t = typename add_const<T>::type;

class A { };

typedef const A A_Const;
class B : public A_Const { }; // expected-warning {{'const' qualifier on base class type 'A_Const' (aka 'const A') have no effect}} \
                              // expected-note {{base class 'A_Const' (aka 'const A') specified here}}

typedef const volatile A A_Const_Volatile;
class C : public A_Const_Volatile { }; // expected-warning {{'const volatile' qualifiers on base class type 'A_Const_Volatile' (aka 'const volatile A') have no effect}} \
                                       // expected-note {{base class 'A_Const_Volatile' (aka 'const volatile A') specified here}}

struct D {
  D(int);
};

template <typename T> struct E : T { // expected-warning {{'const' qualifier on base class type 'const D' have no effect}} \
                                     // expected-note {{base class 'const D' specified here}}
  using T::T;
  E(int &) : E(0) {}
};
E<const D> e(1); // expected-note {{in instantiation of template class 'E<const D>' requested here}}

template <typename T>
struct G : add_const<T>::type { // expected-warning {{'const' qualifier on base class type 'add_const<D>::type' (aka 'const D') have no effect}} \
                                // expected-note {{base class 'add_const<D>::type' (aka 'const D') specified here}}
  using T::T;
  G(int &) : G(0) {}
};
G<D> g(1); // expected-note {{in instantiation of template class 'G<D>' requested here}}