[PATCH] D119051: Fix pod-packed functionality to use the C++11 definition of pod-ness

David Blaikie via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 8 11:19:22 PST 2022


dblaikie added a comment.

Yeah, looks like GCC believes `cxx11_pod::t1` to be C++03 POD even though it doesn't quite follow the letter of the standard - but since teh "= default" is an extension, I guess they get to define what that extension means.

Here's an example:

  struct t1 { int i; };
  #if USER_DECLARED
  struct t2 { t2() = default; int i; };
  #endif
  #if USER_DEFINED
  struct t3 { t3(); int i; };
  #endif
  void f(int i) {
    switch (i) {
      t1 v1;
  #if USER_DECLARED
      t2 v2;
  #endif
  #if USER_DEFINED
      t3 v3;
  #endif
      case 1: {
      }
    }
  }

  $ g++ pod.cpp -std=c++03 -fsyntax-only -w -DUSER_DECLARED
  $ g++ pod.cpp -std=c++03 -fsyntax-only -w -DUSER_DEFINED
  pod.cpp: In function ‘void f(int)’:
  pod.cpp:17:10: error: jump to case label
     17 |     case 1: {
        |          ^
  pod.cpp:15:8: note:   crosses initialization of ‘t3 v3’
     15 |     t3 v3;
        |        ^~

  $ clang++ pod.cpp -std=c++03 -fsyntax-only -w -DUSER_DEFINED
  pod.cpp:17:5: error: cannot jump from switch statement to this case label
      case 1: {
      ^
  pod.cpp:15:8: note: jump bypasses variable initialization
      t3 v3;
         ^
  1 error generated.
  $ clang++ pod.cpp -std=c++03 -fsyntax-only -w -DUSER_DECLARED
  pod.cpp:17:5: error: cannot jump from switch statement to this case label
      case 1: {
      ^
  pod.cpp:12:8: note: jump bypasses initialization of non-POD variable
      t2 v2;
         ^
  1 error generated.

And with the updated version of this patch, we get this behavior, matching GCC's:

  $ clang++-tot pod.cpp -std=c++03 -fsyntax-only -w -DUSER_DECLARED
  $ clang++-tot pod.cpp -std=c++03 -fsyntax-only -w -DUSER_DEFINED
  pod.cpp:17:5: error: cannot jump from switch statement to this case label
      case 1: {
      ^
  pod.cpp:15:8: note: jump bypasses variable initialization
      t3 v3;
         ^
  1 error generated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119051/new/

https://reviews.llvm.org/D119051



More information about the cfe-commits mailing list