Commit 86b5eabf authored by Aaron Ballman's avatar Aaron Ballman
Browse files

Allow parameter names to be elided in a function definition in C.

WG14 has adopted N2480 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2480.pdf)
into C2x at the meetings last week, allowing parameter names of a function
definition to be elided. This patch relaxes the error so that C++ and C2x do not
diagnose this situation, and modes before C2x will allow it as an extension.

This also adds the same feature to ObjC blocks under the assumption that ObjC
wishes to follow the C standard in this regard.
parent f8b65292
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -985,6 +985,9 @@ def C11 : DiagGroup<"c11-extensions">;
// A warning group for warnings about using C99 features as extensions.
def C99 : DiagGroup<"c99-extensions", [C99Designator]>;

// A warning group for warnings about using C2x features as extensions.
def C2x : DiagGroup<"c2x-extensions">;

// A warning group for warnings about GCC extensions.
def GNU : DiagGroup<"gnu", [GNUAlignofExpression, GNUAnonymousStruct,
                            GNUAutoType,
+3 −1
Original line number Diff line number Diff line
@@ -275,7 +275,9 @@ def err_bad_parameter_name : Error<
  "%0 cannot be the name of a parameter">;
def err_bad_parameter_name_template_id : Error<
  "parameter name cannot have template arguments">;
def err_parameter_name_omitted : Error<"parameter name omitted">;
def ext_parameter_name_omitted_c2x : ExtWarn<
  "omitting the parameter name in a function definition is a C2x extension">,
  InGroup<C2x>;
def err_anyx86_interrupt_attribute : Error<
  "%select{x86|x86-64}0 'interrupt' attribute only applies to functions that "
  "have %select{a 'void' return type|"
+6 −5
Original line number Diff line number Diff line
@@ -12883,11 +12883,12 @@ bool Sema::CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters,
    // C99 6.9.1p5: If the declarator includes a parameter type list, the
    // declaration of each parameter shall include an identifier.
    if (CheckParameterNames &&
        Param->getIdentifier() == nullptr &&
        !Param->isImplicit() &&
        !getLangOpts().CPlusPlus)
      Diag(Param->getLocation(), diag::err_parameter_name_omitted);
    if (CheckParameterNames && Param->getIdentifier() == nullptr &&
        !Param->isImplicit() && !getLangOpts().CPlusPlus) {
      // Diagnose this as an extension in C17 and earlier.
      if (!getLangOpts().C2x)
        Diag(Param->getLocation(), diag::ext_parameter_name_omitted_c2x);
    }
    // C99 6.7.5.3p12:
    //   If the function declarator is not part of a definition of that
+6 −5
Original line number Diff line number Diff line
@@ -14646,11 +14646,12 @@ void Sema::ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo,
  if (ExplicitSignature) {
    for (unsigned I = 0, E = ExplicitSignature.getNumParams(); I != E; ++I) {
      ParmVarDecl *Param = ExplicitSignature.getParam(I);
      if (Param->getIdentifier() == nullptr &&
          !Param->isImplicit() &&
          !Param->isInvalidDecl() &&
          !getLangOpts().CPlusPlus)
        Diag(Param->getLocation(), diag::err_parameter_name_omitted);
      if (Param->getIdentifier() == nullptr && !Param->isImplicit() &&
          !Param->isInvalidDecl() && !getLangOpts().CPlusPlus) {
        // Diagnose this as an extension in C17 and earlier.
        if (!getLangOpts().C2x)
          Diag(Param->getLocation(), diag::ext_parameter_name_omitted_c2x);
      }
      Params.push_back(Param);
    }
+2 −2
Original line number Diff line number Diff line
@@ -31,8 +31,8 @@ int main(int argc, char** argv) {

// radar 7528255
void f0() {
  ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \
				 	   // expected-error {{parameter name omitted}}
  ^(int, double d, char) {}(1, 1.34, 'a'); // expected-warning {{omitting the parameter name in a function definition is a C2x extension}} \
                                           // expected-warning {{omitting the parameter name in a function definition is a C2x extension}}
}

// rdar://problem/8962770
Loading