Commit c5b1e744 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r228792:

------------------------------------------------------------------------
r228792 | rsmith | 2015-02-10 18:41:33 -0800 (Tue, 10 Feb 2015) | 5 lines

Add a warning for direct-list-initialization of a variable with a deduced type
(or of a lambda init-capture, which is sort-of such a variable). The semantics
of such constructs will change when we implement N3922, so we intend to warn on
this in Clang 3.6 then change the semantics in Clang 3.7.

------------------------------------------------------------------------

llvm-svn: 228799
parent fece094b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -749,3 +749,6 @@ def SerializedDiagnostics : DiagGroup<"serialized-diagnostics">;
// A warning group for warnings about code that clang accepts when
// compiling CUDA C/C++ but which is not compatible with the CUDA spec.
def CudaCompat : DiagGroup<"cuda-compat">;

// A warning group for things that will change semantics in the future.
def FutureCompat : DiagGroup<"future-compat">;
+4 −0
Original line number Diff line number Diff line
@@ -802,6 +802,10 @@ def warn_cxx98_compat_lambda : Warning<
def err_lambda_missing_parens : Error<
  "lambda requires '()' before %select{'mutable'|return type|"
  "attribute specifier}0">;
def warn_init_capture_direct_list_init : Warning<
  "direct list initialization of a lambda init-capture will change meaning in "
  "a future version of Clang; insert an '=' to avoid a change in behavior">,
  InGroup<FutureCompat>;

// Availability attribute
def err_expected_version : Error<
+4 −0
Original line number Diff line number Diff line
@@ -1635,6 +1635,10 @@ def err_auto_var_init_multiple_expressions : Error<
def err_auto_var_init_paren_braces : Error<
  "cannot deduce type for variable %0 with type %1 from "
  "parenthesized initializer list">;
def warn_auto_var_direct_list_init : Warning<
  "direct list initialization of a variable with a deduced type will change "
  "meaning in a future version of Clang; insert an '=' to avoid a change in "
  "behavior">, InGroup<FutureCompat>;
def err_auto_new_ctor_multiple_expressions : Error<
  "new expression for type %0 contains multiple constructor arguments">;
def err_auto_missing_trailing_return : Error<
+8 −3
Original line number Diff line number Diff line
@@ -894,11 +894,16 @@ Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro,
        // to save the necessary state, and restore it later.
        EnterExpressionEvaluationContext EC(Actions,
                                            Sema::PotentiallyEvaluated);
        TryConsumeToken(tok::equal);
        bool HadEquals = TryConsumeToken(tok::equal);

        if (!SkippedInits)
        if (!SkippedInits) {
          // Warn on constructs that will change meaning when we implement N3922
          if (!HadEquals && Tok.is(tok::l_brace)) {
            Diag(Tok, diag::warn_init_capture_direct_list_init)
              << FixItHint::CreateInsertion(Tok.getLocation(), "=");
          }
          Init = ParseInitializer();
        else if (Tok.is(tok::l_brace)) {
        } else if (Tok.is(tok::l_brace)) {
          BalancedDelimiterTracker Braces(*this, tok::l_brace);
          Braces.consumeOpen();
          Braces.skipToEnd();
+8 −0
Original line number Diff line number Diff line
@@ -8702,6 +8702,14 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init,
    CheckVariableDeclarationType(VDecl);
    if (VDecl->isInvalidDecl())
      return;
    // If all looks well, warn if this is a case that will change meaning when
    // we implement N3922.
    if (DirectInit && !CXXDirectInit && isa<InitListExpr>(Init)) {
      Diag(Init->getLocStart(),
           diag::warn_auto_var_direct_list_init)
        << FixItHint::CreateInsertion(Init->getLocStart(), "=");
    }
  }
  // dllimport cannot be used on variable definitions.
Loading