[PATCH] D123649: Allow flexible array initialization in C++.
    Erich Keane via Phabricator via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Wed Apr 13 06:04:41 PDT 2022
    
    
  
erichkeane added inline comments.
================
Comment at: clang/lib/CodeGen/CGDecl.cpp:346
+    else if (!D.getFlexibleArrayInitChars(getContext()).isZero())
+      CGM.ErrorUnsupported(D.getInit(), "flexible array init");
     else if (HaveInsertPoint()) {
----------------
Can you write a test for this with a 'fixme'?  I don't see a reason why we shouldn't support this eventually.
================
Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4617
       if (getLangOpts().CPlusPlus) {
+        if (!InitDecl->getFlexibleArrayInitChars(getContext()).isZero())
+          ErrorUnsupported(D, "flexible array initializer");
----------------
Same comment here.
================
Comment at: clang/test/SemaCXX/constant-expression-cxx11.cpp:2388
+  // evaluation. Make sure we emit a sane error message, for now.
+  constexpr A c = {1, 2, 3}; // expected-warning {{flexible array initialization is a GNU extension}}
+  static_assert(c.arr[0] == 1, ""); // expected-error {{constant expression}} expected-note {{array member without known bound}}
----------------
I would expect this to be an error, not the static-assert.  The constexpr variable means 'initializable as a constant expression'.  
I'm guessing the problem is ACTUALLY that we support constexpr init, but not the operator[].  I think I'd like to have us have the initialization fail here, since it isn't otherwise usable.
Repository:
  rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123649/new/
https://reviews.llvm.org/D123649
    
    
More information about the cfe-commits
mailing list