[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 13 12:53:52 PDT 2023


efriedma added a comment.

Do we need CodeGen testcases here for full coverage?  The testcases from the issue passed with -fsyntax-only.

--------

With this patch, the following cases produce errors that don't really make sense to me:

  consteval int f(int x) {
      return x;
  }
  struct SS {
      int y;
      int x = f(this->y);
      constexpr SS(int yy) : y(yy) {}
  };
  SS s = {1};



  <stdin>:6:13: error: call to consteval function 'f' is not a constant expression
      6 |     int x = f(this->y);
        |             ^
  <stdin>:7:15: note: in the default initializer of 'x'
      7 |     constexpr SS(int yy) : y(yy) {}
        |               ^
  <stdin>:6:5: note: declared here
      6 |     int x = f(this->y);
        |     ^
  <stdin>:6:15: note: use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
      6 |     int x = f(this->y);
        |               ^
  1 error generated.



  consteval int f(int x) {
      return x;
  }
  struct SS {
      int y;
      int x = f(this->y);
      consteval SS(int yy) : y(yy) {}
  };
  SS s = {1};

  <stdin>:6:13: error: cannot take address of consteval function 'f' outside of an immediate invocation
      6 |     int x = f(this->y);
        |             ^
  <stdin>:1:15: note: declared here
      1 | consteval int f(int x) {
        |               ^
  1 error generated.

Somehow the following is accepted, though:

  consteval int f(int x) {
      return x;
  }
  struct SS {
      int y;
      int x = f(this->y);
      template<typename T> constexpr SS(T yy) : y(yy) {}
  };
  SS s = {1};


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175



More information about the cfe-commits mailing list