Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ Improvements to Clang's diagnostics
scope.Unlock();
require(scope); // Warning! Requires mu1.
}
- Clang now emits a ``-Wignored-qualifiers`` diagnostic when a base class includes cv-qualifiers (#GH55474).

Improvements to Clang's time-trace
----------------------------------
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ def err_noreturn_non_function : Error<
def warn_qual_return_type : Warning<
"'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">,
InGroup<IgnoredQualifiers>, DefaultIgnore;
def warn_qual_base_type : Warning<
"'%0' qualifier%s1 on base class type %2 have no effect">,
InGroup<IgnoredQualifiers>, DefaultIgnore;

def warn_deprecated_redundant_constexpr_static_def : Warning<
"out-of-line definition of constexpr static data member is redundant "
"in C++17 and is deprecated">,
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,15 @@ CXXBaseSpecifier *Sema::CheckBaseSpecifier(CXXRecordDecl *Class,
return nullptr;
}

if (BaseType.hasQualifiers()) {
std::string Quals =
BaseType.getQualifiers().getAsString(Context.getPrintingPolicy());
Diag(BaseLoc, diag::warn_qual_base_type)
<< Quals << std::count(Quals.begin(), Quals.end(), ' ') + 1
<< BaseType;
Diag(BaseLoc, diag::note_base_class_specified_here) << BaseType;
}

// For the MS ABI, propagate DLL attributes to base class templates.
if (Context.getTargetInfo().getCXXABI().isMicrosoft() ||
Context.getTargetInfo().getTriple().isPS()) {
Expand Down
35 changes: 35 additions & 0 deletions clang/test/SemaCXX/warn-base-type-qualifiers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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}}
Loading