r183881 - Add -Wdeprecated warnings and fixits for things deprecated in C++11:

Nico Weber thakis at chromium.org
Thu Jun 27 13:06:58 PDT 2013


On Fri, Jun 14, 2013 at 2:06 PM, Richard Smith <richard at metafoo.co.uk>wrote:

> On Fri, Jun 14, 2013 at 11:45 AM, David Blaikie <dblaikie at gmail.com>
> wrote:
> > On Wed, Jun 12, 2013 at 7:02 PM, Richard Smith
> > <richard-llvm at metafoo.co.uk> wrote:
> >> Author: rsmith
> >> Date: Wed Jun 12 21:02:51 2013
> >> New Revision: 183881
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=183881&view=rev
> >> Log:
> >> Add -Wdeprecated warnings and fixits for things deprecated in C++11:
> >>  - 'register' storage class
> >
> > This is firing in system headers while building compiler-rt. Should we
> > suppress it in system headers?
>
> Well, it should already be suppressed in system headers, but it looks
> like we should also give this the special suppress-in-system-macros
> treatment. Done in r184005.
>

Is this a useful warning? Code generated by flex for example contains
register variables, and there doesn't seem much harm in that. Should this
be in -pedantic?


>
> > .../llvm/src/projects/compiler-rt/lib/msan/tests/msan_test.cc:661:25:
> > warning: 'register' storage class specifier is deprecated
> > [-Wdeprecated]
> >   sai.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
> >                         ^
> > /usr/include/netinet/in.h:393:21: note: expanded from macro 'htonl'
> > #   define htonl(x)     __bswap_32 (x)
> >                         ^
> > /usr/include/x86_64-linux-gnu/bits/byteswap.h:71:10: note: expanded
> > from macro '__bswap_32'
> >       ({ register unsigned int __v, __x = (x);
>      \
> >          ^
> > 1 warning generated.
> >
> >>  - dynamic exception specifications
> >>
> >> Only the former check is enabled by default for now (the latter might
> be quite noisy).
> >>
> >> Added:
> >>     cfe/trunk/test/SemaCXX/deprecated.cpp
> >> Modified:
> >>     cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> >>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> >>     cfe/trunk/lib/Parse/ParseDecl.cpp
> >>     cfe/trunk/lib/Parse/ParseDeclCXX.cpp
> >>     cfe/trunk/test/CXX/class/class.friend/p6.cpp
> >>     cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
> >>     cfe/trunk/test/FixIt/fixit-cxx0x.cpp
> >>     cfe/trunk/test/Sema/thread-specifier.c
> >>     cfe/trunk/test/SemaCXX/attr-cxx0x.cpp
> >>
> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=183881&r1=183880&r2=183881&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
> >> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Wed Jun 12
> 21:02:51 2013
> >> @@ -309,6 +309,8 @@ def err_expected_class_name_not_template
> >>    Error<"'typename' is redundant; base classes are implicitly types">;
> >>  def err_unspecified_vla_size_with_static : Error<
> >>    "'static' may not be used with an unspecified variable length array
> size">;
> >> +def warn_deprecated_register : Warning<
> >> +  "'register' storage class specifier is deprecated">,
> InGroup<Deprecated>;
> >>
> >>  def err_expected_case_before_expression: Error<
> >>    "expected 'case' keyword before expression">;
> >>
> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=183881&r1=183880&r2=183881&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> >> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jun 12
> 21:02:51 2013
> >> @@ -287,6 +287,10 @@ def note_using_decl : Note<"%select{|pre
> >>  def warn_access_decl_deprecated : Warning<
> >>    "access declarations are deprecated; use using declarations
> instead">,
> >>    InGroup<Deprecated>;
> >> +def warn_exception_spec_deprecated : Warning<
> >> +  "dynamic exception specifications are deprecated">,
> >> +  InGroup<Deprecated>, DefaultIgnore;
> >> +def note_exception_spec_deprecated : Note<"use '%0' instead">;
> >>
> >>  def warn_global_constructor : Warning<
> >>    "declaration requires a global constructor">,
> >>
> >> Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=183881&r1=183880&r2=183881&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
> >> +++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Jun 12 21:02:51 2013
> >> @@ -2771,6 +2771,9 @@ void Parser::ParseDeclarationSpecifiers(
> >>                                             PrevSpec, DiagID);
> >>        break;
> >>      case tok::kw_register:
> >> +      if (getLangOpts().CPlusPlus11)
> >> +        Diag(Tok, diag::warn_deprecated_register)
> >> +          << FixItHint::CreateRemoval(Tok.getLocation());
> >>        isInvalid = DS.SetStorageClassSpec(Actions,
> DeclSpec::SCS_register, Loc,
> >>                                           PrevSpec, DiagID);
> >>        break;
> >>
> >> Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=183881&r1=183880&r2=183881&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
> >> +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Jun 12 21:02:51 2013
> >> @@ -2893,6 +2893,16 @@ Parser::tryParseExceptionSpecification(
> >>    return Result;
> >>  }
> >>
> >> +static void diagnoseDynamicExceptionSpecification(
> >> +    Parser &P, const SourceRange &Range, bool IsNoexcept) {
> >> +  if (P.getLangOpts().CPlusPlus11) {
> >> +    const char *Replacement = IsNoexcept ? "noexcept" :
> "noexcept(false)";
> >> +    P.Diag(Range.getBegin(), diag::warn_exception_spec_deprecated) <<
> Range;
> >> +    P.Diag(Range.getBegin(), diag::note_exception_spec_deprecated)
> >> +      << Replacement << FixItHint::CreateReplacement(Range,
> Replacement);
> >> +  }
> >> +}
> >> +
> >>  /// ParseDynamicExceptionSpecification - Parse a C++
> >>  /// dynamic-exception-specification (C++ [except.spec]).
> >>  ///
> >> @@ -2926,6 +2936,7 @@ ExceptionSpecificationType Parser::Parse
> >>        Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
> >>      T.consumeClose();
> >>      SpecificationRange.setEnd(T.getCloseLocation());
> >> +    diagnoseDynamicExceptionSpecification(*this, SpecificationRange,
> false);
> >>      return EST_MSAny;
> >>    }
> >>
> >> @@ -2957,6 +2968,8 @@ ExceptionSpecificationType Parser::Parse
> >>
> >>    T.consumeClose();
> >>    SpecificationRange.setEnd(T.getCloseLocation());
> >> +  diagnoseDynamicExceptionSpecification(*this, SpecificationRange,
> >> +                                        Exceptions.empty());
> >>    return Exceptions.empty() ? EST_DynamicNone : EST_Dynamic;
> >>  }
> >>
> >>
> >> Modified: cfe/trunk/test/CXX/class/class.friend/p6.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.friend/p6.cpp?rev=183881&r1=183880&r2=183881&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/test/CXX/class/class.friend/p6.cpp (original)
> >> +++ cfe/trunk/test/CXX/class/class.friend/p6.cpp Wed Jun 12 21:02:51
> 2013
> >> @@ -4,7 +4,11 @@
> >>  class A {
> >>    friend static class B; // expected-error {{'static' is invalid in
> friend declarations}}
> >>    friend extern class C; // expected-error {{'extern' is invalid in
> friend declarations}}
> >> +#if __cplusplus < 201103L
> >>    friend register class E; // expected-error {{'register' is invalid
> in friend declarations}}
> >> +#else
> >> +  friend register class E; // expected-error {{'register' is invalid
> in friend declarations}} expected-warning {{deprecated}}
> >> +#endif
> >>    friend mutable class F; // expected-error {{'mutable' is invalid in
> friend declarations}}
> >>    friend typedef class G; // expected-error {{'typedef' is invalid in
> friend declarations}}
> >>    friend __thread class G; // expected-error {{'__thread' is invalid
> in friend declarations}}
> >>
> >> Modified: cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp?rev=183881&r1=183880&r2=183881&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp (original)
> >> +++ cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp Wed Jun
> 12 21:02:51 2013
> >> @@ -117,7 +117,7 @@ void g() {
> >>
> >>    for (extern int a : A()) {} // expected-error {{loop variable 'a'
> may not be declared 'extern'}}
> >>    for (static int a : A()) {} // expected-error {{loop variable 'a'
> may not be declared 'static'}}
> >> -  for (register int a : A()) {} // expected-error {{loop variable 'a'
> may not be declared 'register'}}
> >> +  for (register int a : A()) {} // expected-error {{loop variable 'a'
> may not be declared 'register'}} expected-warning {{deprecated}}
> >>    for (constexpr int a : A()) {} // expected-error {{loop variable 'a'
> may not be declared 'constexpr'}}
> >>
> >>    for (auto u : X::NoBeginADL()) { // expected-error {{invalid range
> expression of type 'X::NoBeginADL'; no viable 'begin' function available}}
> >>
> >> Modified: cfe/trunk/test/FixIt/fixit-cxx0x.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-cxx0x.cpp?rev=183881&r1=183880&r2=183881&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/test/FixIt/fixit-cxx0x.cpp (original)
> >> +++ cfe/trunk/test/FixIt/fixit-cxx0x.cpp Wed Jun 12 21:02:51 2013
> >> @@ -132,3 +132,8 @@ namespace NonStaticConstexpr {
> >>      }
> >>    };
> >>  }
> >> +
> >> +int RegisterVariable() {
> >> +  register int n; // expected-warning {{'register' storage class
> specifier is deprecated}}
> >> +  return n;
> >> +}
> >>
> >> Modified: cfe/trunk/test/Sema/thread-specifier.c
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/thread-specifier.c?rev=183881&r1=183880&r2=183881&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/test/Sema/thread-specifier.c (original)
> >> +++ cfe/trunk/test/Sema/thread-specifier.c Wed Jun 12 21:02:51 2013
> >> @@ -2,8 +2,8 @@
> >>  // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only
> -Wno-private-extern -verify -pedantic -x c++ %s -DGNU
> >>  // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only
> -Wno-private-extern -verify -pedantic %s -DC11 -D__thread=_Thread_local
> >>  // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only
> -Wno-private-extern -verify -pedantic -x c++ %s -DC11
> -D__thread=_Thread_local
> >> -// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only
> -Wno-private-extern -verify -pedantic -x c++ %s -DCXX11
> -D__thread=thread_local -std=c++11
> >> -// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only
> -Wno-private-extern -verify -pedantic -x c++ %s -DC11
> -D__thread=_Thread_local -std=c++11
> >> +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only
> -Wno-private-extern -verify -pedantic -x c++ %s -DCXX11
> -D__thread=thread_local -std=c++11 -Wno-deprecated
> >> +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only
> -Wno-private-extern -verify -pedantic -x c++ %s -DC11
> -D__thread=_Thread_local -std=c++11 -Wno-deprecated
> >>
> >>  #ifdef __cplusplus
> >>  // In C++, we define __private_extern__ to extern.
> >>
> >> Modified: cfe/trunk/test/SemaCXX/attr-cxx0x.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-cxx0x.cpp?rev=183881&r1=183880&r2=183881&view=diff
> >>
> ==============================================================================
> >> --- cfe/trunk/test/SemaCXX/attr-cxx0x.cpp (original)
> >> +++ cfe/trunk/test/SemaCXX/attr-cxx0x.cpp Wed Jun 12 21:02:51 2013
> >> @@ -12,7 +12,7 @@ struct align_member {
> >>  };
> >>
> >>  void f(alignas(1) char c) { // expected-error {{'alignas' attribute
> cannot be applied to a function parameter}}
> >> -  alignas(1) register char k; // expected-error {{'alignas' attribute
> cannot be applied to a variable with 'register' storage class}}
> >> +  alignas(1) register char k; // expected-error {{'alignas' attribute
> cannot be applied to a variable with 'register' storage class}}
> expected-warning {{deprecated}}
> >>    try {
> >>    } catch (alignas(4) int n) { // expected-error {{'alignas' attribute
> cannot be applied to a 'catch' variable}}
> >>    }
> >>
> >> Added: cfe/trunk/test/SemaCXX/deprecated.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/deprecated.cpp?rev=183881&view=auto
> >>
> ==============================================================================
> >> --- cfe/trunk/test/SemaCXX/deprecated.cpp (added)
> >> +++ cfe/trunk/test/SemaCXX/deprecated.cpp Wed Jun 12 21:02:51 2013
> >> @@ -0,0 +1,31 @@
> >> +// RUN: %clang_cc1 -std=c++98 %s -Wdeprecated -verify
> >> +// RUN: %clang_cc1 -std=c++11 %s -Wdeprecated -verify
> >> +// RUN: %clang_cc1 -std=c++1y %s -Wdeprecated -verify
> >> +
> >> +void f() throw();
> >> +void g() throw(int);
> >> +void h() throw(...);
> >> +#if __cplusplus >= 201103L
> >> +// expected-warning at -4 {{dynamic exception specifications are
> deprecated}} expected-note at -4 {{use 'noexcept' instead}}
> >> +// expected-warning at -4 {{dynamic exception specifications are
> deprecated}} expected-note at -4 {{use 'noexcept(false)' instead}}
> >> +// expected-warning at -4 {{dynamic exception specifications are
> deprecated}} expected-note at -4 {{use 'noexcept(false)' instead}}
> >> +#endif
> >> +
> >> +void stuff() {
> >> +  register int n;
> >> +#if __cplusplus >= 201103L
> >> +  // expected-warning at -2 {{'register' storage class specifier is
> deprecated}}
> >> +#endif
> >> +
> >> +  bool b;
> >> +  ++b; // expected-warning {{incrementing expression of type bool is
> deprecated}}
> >> +
> >> +  // FIXME: This is ill-formed in C++11.
> >> +  char *p = "foo"; // expected-warning {{conversion from string
> literal to 'char *' is deprecated}}
> >> +}
> >> +
> >> +struct S { int n; };
> >> +struct T : private S {
> >> +  // FIXME: This is ill-formed in C++11.
> >> +  S::n; // expected-warning {{access declarations are deprecated; use
> using declarations instead}}
> >> +};
> >>
> >>
> >> _______________________________________________
> >> cfe-commits mailing list
> >> cfe-commits at cs.uiuc.edu
> >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130627/7c1857fa/attachment.html>


More information about the cfe-commits mailing list