[all-commits] [llvm/llvm-project] 5955a0: Allow flexible array initialization in C++.

Eli Friedman via All-commits all-commits at lists.llvm.org
Thu Apr 14 11:57:14 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5955a0f9375a8c0b134eeb4a8de5155dcce7c94f
      https://github.com/llvm/llvm-project/commit/5955a0f9375a8c0b134eeb4a8de5155dcce7c94f
  Author: Eli Friedman <efriedma at quicinc.com>
  Date:   2022-04-14 (Thu, 14 Apr 2022)

  Changed paths:
    M clang/include/clang/AST/Decl.h
    M clang/include/clang/Basic/DiagnosticASTKinds.td
    M clang/lib/AST/Decl.cpp
    M clang/lib/AST/ExprConstant.cpp
    M clang/lib/CodeGen/CGDecl.cpp
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/lib/Sema/SemaInit.cpp
    A clang/test/CodeGenCXX/flexible-array-init.cpp
    M clang/test/SemaCXX/constant-expression-cxx11.cpp

  Log Message:
  -----------
  Allow flexible array initialization in C++.

Flexible array initialization is a C/C++ extension implemented in many
compilers to allow initializing the flexible array tail of a struct type
that contains a flexible array. In clang, this is currently restricted
to C. But this construct is used in the Microsoft SDK headers, so I'd
like to extend it to C++.

For now, this doesn't handle dynamic initialization; probably not hard
to implement, but it's extra code, and I don't think it's necessary for
the expected uses.  And we explicitly fail out of constant evaluation.

I've added some additional code to assert that initializers have the
correct size, with or without flexible array init. This might catch
issues unrelated to flexible array init.

Differential Revision: https://reviews.llvm.org/D123649




More information about the All-commits mailing list