7.7 Constant expressions [expr.const] C++N4910:2022 (70) p150.cpp

# はじめに(Introduction)

N4910  Working Draft, Standard for Programming Language C++

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf

n4910は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM）との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。

 <この項は書きかけです。順次追記します。>

 

## 背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに１回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。

この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を１０種類以上、最近になって解決できたことがあります。それは、主に次の３つの情報に基づいています。

https://stackoverflow.com
https://cpprefjp.github.io
http://ja.cppreference.com/

また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。


## 作業方針(sequence)
Clang++では-std=c++03, C++2bの2種類
g++では-std=c++03, c++2bの２種類
でコンパイルし、

１）コンパイルエラーを収集する。
２）コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
３）リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
４）意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。

１）だけのものから４）まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。


### C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list  

https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91


### C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010

### C++N4606, 2016符号断片編纂一覧(example code compile list)
C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/

### C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318

## 編纂器(Compiler)
### clang++ --version
> Debian clang version 14.0.5-++20220610033153+c12386ae247c-1~exp1~20220610153237.151
Target: x86_64-pc-linux-gnu, Thread model: posix, InstalledDir: /usr/bin

### g++- --version
> g++ (GCC) 12.1.0  Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

#  7.7 Constant expressions [expr.const] C++N4910:2022 (70) p150.cpp

## 算譜(source code)

```c++:p150.cpp
// C++N4910 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf
const char * msg=" 7.7 Constant expressions [expr.const] C++N4910:2022 (70) p150.cpp";
// Debian clang version 14.0.5-++20220610033153+c12386ae247c-
// g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.
// C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list
// https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91

#include <iostream>
#include <cstdlib> 
#include <cstring>
#include <cassert>
#include <coroutine>

using namespace std;

// Example 1  
void g() {
const int n = 0;
[=] {
constexpr int i = n; // OK, n is not odr-used here
constexpr int j = *&n; // error: &n would be an odr-use of n
};
}
// [Example 2 :
auto monad = [](auto v) { return [=] { return v; }; };
auto bind = [](auto m) {
return [=](auto fvm) { return fvm(m()); };
};
// OK to capture objects with automatic storage duration created during constant expression evaluation.
static_assert(bind(monad(2))(monad)() == monad(2)());
// [Example 3 :
int x; // not constant
struct A {
constexpr A(bool b) : m3(b?42:x) { }
int m3;
};
constexpr int v = A(true).m3; // OK, constructor call initializes m with the value 42
constexpr int w = A(false).m3; // error: initializer for m is x, which is non-constant
constexpr int f1(int k) {
constexpr int x = k; // error: x is not initialized by a constant expression
// because lifetime of k began outside the initializer of x
return x;
}
constexpr int f2(int k) {
int x = k; // OK, not required to be a constant expression
// because x is not constexpr
return x;
}
constexpr int incr(int &n3) {
return ++n3;
}
constexpr int g3(int k) {
constexpr int x = incr(k); // error: incr(k) is not a core constant expression
// because lifetime of k began outside the expression incr(k)
return x;
}
constexpr int h(int k) {
int x = incr(k); // OK, incr(k) is not required to be a core constant expression
return x;
}
constexpr int y = h(1); // OK, initializes y with the value 2
// h(1) is a core constant expression because
// the lifetime of k begins inside h(1)
// [Example 4 :
struct A4 {
constexpr A4(int i) : val(i) { }
constexpr operator int() const { return val; }
constexpr operator long() const { return 42; }
private:
int val;
};
constexpr A4 a = alignof(int);
alignas(a) int n; // error: ambiguous conversion
struct B { int n : a; }; // error: ambiguous conversion
// Example 5 :
consteval int f() { return 42; }
consteval auto g5() { return f; }
consteval int h5(int (*p)() = g5()) { return p(); }
constexpr int r = h5(); // OK
constexpr auto e = g5(); // error: a pointer to an immediate function is
// not a permitted result of a constant expression
// [Example 6 :
bool f6() {
char array[1 + int(1 + 0.2 - 0.1 - 0.1)]; // Must be evaluated during translation
int size = 1 + int(1 + 0.2 - 0.1 - 0.1); // May be evaluated at runtime
return sizeof(array) == size;
}
// It is unspecified whether the value of f() will be true or false. —
// [Example 7 :
template<bool> struct X7 {};
X7<std::is_constant_evaluated()> x7; // type X<true>
int y7;
const int a7 = std::is_constant_evaluated() ? y7 : 1; // dynamic initialization to 1
double z[a7]; // error: a is not usable
// in constant expressions
const int b = std::is_constant_evaluated() ? 2 : y7; // static initialization to 2
int c = y7 + (std::is_constant_evaluated() ? 2 : y7); // dynamic initialization to y+y
constexpr int f7() {
const int n7 = std::is_constant_evaluated() ? 13 : 17; // n is 13
int m7 = std::is_constant_evaluated() ? 13 : 17; // m can be 13 or 17 (see below)
char arr[n7] = {}; // char[13]
return m7 + sizeof(arr);
}
int p = f7(); // m is 13; initialized to 26
int q = p + f7(); // m is 17 for this call; initialized to 56
int main(){
  cout  <<  msg << endl;
  return EXIT_SUCCESS;
}
```

## Script

```bash:clgc.sh
#!/bin/sh
rm $1l
rm $1g
echo "$ clang++ $1.cpp -std=03 -o $1l -I. -Wall" 
clang++ $1.cpp -std=c++03 -o $1l -I. -Wall
if [  -e $1l ]; then
./$1l 
fi
rm $1l
echo "$ clang++ $1.cpp -std=2b -o $1l -I. -Wall"
clang++ $1.cpp -std=c++2b -o $1l -I. -Wall
if [  -e $1l ]; then
./$1l
fi
echo "\r"
echo "$ g++ $1.cpp -std=03 -o $1g -I. -Wall"
g++ $1.cpp -std=c++03 -o $1g -I. -Wall
if [ -e $1g ]; then
./$1g
fi
rm $1g
echo "\r"
echo "$ g++ $1.cpp -std=2b -o $1g -I. -Wall"
g++ $1.cpp -std=c++2b -o $1g -I. -Wall
if [ -e $1g ]; then
./$1g 
fi
```
## 編纂・実行結果(compile and go)

```ubuntu:bash
# ./clgc.sh  p150
rm: cannot remove 'p150l': No such file or directory
rm: cannot remove 'p150g': No such file or directory
$ clang++ p150.cpp -std=03 -o p150l -I. -Wall
p150.cpp:21:1: error: expected expression
[=] {
^
p150.cpp:27:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto monad = [](auto v) { return [=] { return v; }; };
^
p150.cpp:27:14: error: expected expression
auto monad = [](auto v) { return [=] { return v; }; };
             ^
p150.cpp:28:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto bind = [](auto m) {
^
p150.cpp:28:13: error: expected expression
auto bind = [](auto m) {
            ^
p150.cpp:32:1: error: C++ requires a type specifier for all declarations
static_assert(bind(monad(2))(monad)() == monad(2)());
^
p150.cpp:36:1: error: unknown type name 'constexpr'
constexpr A(bool b) : m3(b?42:x) { }
^
p150.cpp:36:11: error: constructor cannot have a return type
constexpr A(bool b) : m3(b?42:x) { }
          ^
p150.cpp:39:1: error: unknown type name 'constexpr'
constexpr int v = A(true).m3; // OK, constructor call initializes m with the value 42
^
p150.cpp:39:19: error: no matching conversion for functional-style cast from 'bool' to 'A'
constexpr int v = A(true).m3; // OK, constructor call initializes m with the value 42
                  ^~~~~~
p150.cpp:35:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'bool' to 'const A' for 1st argument
struct A {
       ^
p150.cpp:35:8: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided
p150.cpp:40:1: error: unknown type name 'constexpr'
constexpr int w = A(false).m3; // error: initializer for m is x, which is non-constant
^
p150.cpp:40:19: error: no matching conversion for functional-style cast from 'bool' to 'A'
constexpr int w = A(false).m3; // error: initializer for m is x, which is non-constant
                  ^~~~~~~
p150.cpp:35:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'bool' to 'const A' for 1st argument
struct A {
       ^
p150.cpp:35:8: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided
p150.cpp:41:1: error: unknown type name 'constexpr'
constexpr int f1(int k) {
^
p150.cpp:42:1: error: unknown type name 'constexpr'
constexpr int x = k; // error: x is not initialized by a constant expression
^
p150.cpp:46:1: error: unknown type name 'constexpr'
constexpr int f2(int k) {
^
p150.cpp:51:1: error: unknown type name 'constexpr'
constexpr int incr(int &n3) {
^
p150.cpp:54:1: error: unknown type name 'constexpr'
constexpr int g3(int k) {
^
p150.cpp:55:1: error: unknown type name 'constexpr'
constexpr int x = incr(k); // error: incr(k) is not a core constant expression
^
p150.cpp:59:1: error: unknown type name 'constexpr'
constexpr int h(int k) {
^
p150.cpp:63:1: error: unknown type name 'constexpr'
constexpr int y = h(1); // OK, initializes y with the value 2
^
p150.cpp:68:1: error: unknown type name 'constexpr'
constexpr A4(int i) : val(i) { }
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
rm: cannot remove 'p150l': No such file or directory
$ clang++ p150.cpp -std=2b -o p150l -I. -Wall
p150.cpp:22:15: warning: unused variable 'i' [-Wunused-variable]
constexpr int i = n; // OK, n is not odr-used here
              ^
p150.cpp:23:15: warning: unused variable 'j' [-Wunused-variable]
constexpr int j = *&n; // error: &n would be an odr-use of n
              ^
p150.cpp:21:1: warning: expression result unused [-Wunused-value]
[=] {
^~~~~
p150.cpp:40:15: error: constexpr variable 'w' must be initialized by a constant expression
constexpr int w = A(false).m3; // error: initializer for m is x, which is non-constant
              ^   ~~~~~~~~~~~
p150.cpp:36:31: note: read of non-const variable 'x' is not allowed in a constant expression
constexpr A(bool b) : m3(b?42:x) { }
                              ^
p150.cpp:40:19: note: in call to 'A(false)'
constexpr int w = A(false).m3; // error: initializer for m is x, which is non-constant
                  ^
p150.cpp:34:5: note: declared here
int x; // not constant
    ^
p150.cpp:42:15: error: constexpr variable 'x' must be initialized by a constant expression
constexpr int x = k; // error: x is not initialized by a constant expression
              ^   ~
p150.cpp:42:19: note: function parameter 'k' with unknown value cannot be used in a constant expression
constexpr int x = k; // error: x is not initialized by a constant expression
                  ^
p150.cpp:41:22: note: declared here
constexpr int f1(int k) {
                     ^
p150.cpp:55:15: error: constexpr variable 'x' must be initialized by a constant expression
constexpr int x = incr(k); // error: incr(k) is not a core constant expression
              ^   ~~~~~~~
p150.cpp:52:8: note: function parameter 'k' with unknown value cannot be used in a constant expression
return ++n3;
       ^
p150.cpp:55:19: note: in call to 'incr(k)'
constexpr int x = incr(k); // error: incr(k) is not a core constant expression
                  ^
p150.cpp:54:22: note: declared here
constexpr int g3(int k) {
                     ^
p150.cpp:75:9: error: ambiguous conversion from type 'const A4' to an integral or unscoped enumeration type
alignas(a) int n; // error: ambiguous conversion
        ^
p150.cpp:69:11: note: conversion to integral type 'int' declared here
constexpr operator int() const { return val; }
          ^
p150.cpp:70:11: note: conversion to integral type 'long' declared here
constexpr operator long() const { return 42; }
          ^
p150.cpp:76:20: error: ambiguous conversion from type 'const A4' to an integral or unscoped enumeration type
struct B { int n : a; }; // error: ambiguous conversion
                   ^
p150.cpp:69:11: note: conversion to integral type 'int' declared here
constexpr operator int() const { return val; }
          ^
p150.cpp:70:11: note: conversion to integral type 'long' declared here
constexpr operator long() const { return 42; }
          ^
p150.cpp:80:31: error: call to consteval function 'g5' is not a constant expression
consteval int h5(int (*p)() = g5()) { return p(); }
                              ^
p150.cpp:80:31: note: pointer to a consteval declaration is not a constant expression
p150.cpp:78:15: note: declared here
consteval int f() { return 42; }
              ^
p150.cpp:80:31: error: cannot take address of consteval function 'g5' outside of an immediate invocation
consteval int h5(int (*p)() = g5()) { return p(); }
                              ^
p150.cpp:79:16: note: declared here
consteval auto g5() { return f; }
               ^
p150.cpp:82:20: error: call to consteval function 'g5' is not a constant expression
constexpr auto e = g5(); // error: a pointer to an immediate function is
                   ^
p150.cpp:82:20: note: pointer to a consteval declaration is not a constant expression
p150.cpp:78:15: note: declared here
consteval int f() { return 42; }
              ^
p150.cpp:82:16: error: constexpr variable 'e' must be initialized by a constant expression
constexpr auto e = g5(); // error: a pointer to an immediate function is
               ^   ~~~~
p150.cpp:82:16: note: pointer to a consteval declaration is not a constant expression
p150.cpp:78:15: note: declared here
consteval int f() { return 42; }
              ^
p150.cpp:93:4: warning: 'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression [-Wconstant-evaluated]
X7<std::is_constant_evaluated()> x7; // type X<true>
   ^
p150.cpp:95:16: warning: 'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression [-Wconstant-evaluated]
const int a7 = std::is_constant_evaluated() ? y7 : 1; // dynamic initialization to 1
               ^
p150.cpp:96:8: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
double z[a7]; // error: a is not usable
       ^
p150.cpp:98:15: warning: 'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression [-Wconstant-evaluated]
const int b = std::is_constant_evaluated() ? 2 : y7; // static initialization to 2
              ^
p150.cpp:101:16: warning: 'std::is_constant_evaluated' will always evaluate to 'true' in a manifestly constant-evaluated expression [-Wconstant-evaluated]
const int n7 = std::is_constant_evaluated() ? 13 : 17; // n is 13
               ^
8 warnings and 9 errors generated.

$ g++ p150.cpp -std=03 -o p150g -I. -Wall
p150.cpp:22:1: warning: identifier 'constexpr' is a keyword in C++11 [-Wc++11-compat]
   22 | constexpr int i = n; // OK, n is not odr-used here
      | ^~~~~~~~~
p150.cpp:32:1: warning: identifier 'static_assert' is a keyword in C++11 [-Wc++11-compat]
   32 | static_assert(bind(monad(2))(monad)() == monad(2)());
      | ^~~~~~~~~~~~~
p150.cpp: In lambda function:
p150.cpp:22:1: error: 'constexpr' was not declared in this scope
   22 | constexpr int i = n; // OK, n is not odr-used here
      | ^~~~~~~~~
p150.cpp:23:10: error: expected ';' before 'int'
   23 | constexpr int j = *&n; // error: &n would be an odr-use of n
      |          ^~~~
      |          ;
p150.cpp: In function 'void g()':
p150.cpp:24:1: warning: lambda expressions only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   24 | };
      | ^
p150.cpp:20:11: warning: unused variable 'n' [-Wunused-variable]
   20 | const int n = 0;
      |           ^
p150.cpp: At global scope:
p150.cpp:27:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   27 | auto monad = [](auto v) { return [=] { return v; }; };
      | ^~~~
      | ----
p150.cpp:27:6: error: 'monad' does not name a type
   27 | auto monad = [](auto v) { return [=] { return v; }; };
      |      ^~~~~
p150.cpp:28:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   28 | auto bind = [](auto m) {
      | ^~~~
      | ----
p150.cpp:28:6: error: 'bind' does not name a type
   28 | auto bind = [](auto m) {
      |      ^~~~
p150.cpp:32:14: error: expected constructor, destructor, or type conversion before '(' token
   32 | static_assert(bind(monad(2))(monad)() == monad(2)());
      |              ^
p150.cpp:36:1: error: 'constexpr' does not name a type
   36 | constexpr A(bool b) : m3(b?42:x) { }
      | ^~~~~~~~~
p150.cpp:36:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:39:1: error: 'constexpr' does not name a type
   39 | constexpr int v = A(true).m3; // OK, constructor call initializes m with the value 42
      | ^~~~~~~~~
p150.cpp:39:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:40:1: error: 'constexpr' does not name a type
   40 | constexpr int w = A(false).m3; // error: initializer for m is x, which is non-constant
      | ^~~~~~~~~
p150.cpp:40:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:41:1: error: 'constexpr' does not name a type
   41 | constexpr int f1(int k) {
      | ^~~~~~~~~
p150.cpp:41:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:46:1: error: 'constexpr' does not name a type
   46 | constexpr int f2(int k) {
      | ^~~~~~~~~
p150.cpp:46:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:51:1: error: 'constexpr' does not name a type
   51 | constexpr int incr(int &n3) {
      | ^~~~~~~~~
p150.cpp:51:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:54:1: error: 'constexpr' does not name a type
   54 | constexpr int g3(int k) {
      | ^~~~~~~~~
p150.cpp:54:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:59:1: error: 'constexpr' does not name a type
   59 | constexpr int h(int k) {
      | ^~~~~~~~~
p150.cpp:59:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:63:1: error: 'constexpr' does not name a type
   63 | constexpr int y = h(1); // OK, initializes y with the value 2
      | ^~~~~~~~~
p150.cpp:63:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:68:1: error: 'constexpr' does not name a type
   68 | constexpr A4(int i) : val(i) { }
      | ^~~~~~~~~
p150.cpp:68:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:69:1: error: 'constexpr' does not name a type
   69 | constexpr operator int() const { return val; }
      | ^~~~~~~~~
p150.cpp:69:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:70:1: error: 'constexpr' does not name a type
   70 | constexpr operator long() const { return 42; }
      | ^~~~~~~~~
p150.cpp:70:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:74:1: error: 'constexpr' does not name a type
   74 | constexpr A4 a = alignof(int);
      | ^~~~~~~~~
p150.cpp:74:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:75:8: error: expected constructor, destructor, or type conversion before '(' token
   75 | alignas(a) int n; // error: ambiguous conversion
      |        ^
p150.cpp:76:20: error: 'a' was not declared in this scope
   76 | struct B { int n : a; }; // error: ambiguous conversion
      |                    ^
p150.cpp:78:1: error: 'consteval' does not name a type
   78 | consteval int f() { return 42; }
      | ^~~~~~~~~
p150.cpp:79:1: error: 'consteval' does not name a type
   79 | consteval auto g5() { return f; }
      | ^~~~~~~~~
p150.cpp:80:1: error: 'consteval' does not name a type
   80 | consteval int h5(int (*p)() = g5()) { return p(); }
      | ^~~~~~~~~
p150.cpp:81:1: error: 'constexpr' does not name a type
   81 | constexpr int r = h5(); // OK
      | ^~~~~~~~~
p150.cpp:81:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:82:1: error: 'constexpr' does not name a type
   82 | constexpr auto e = g5(); // error: a pointer to an immediate function is
      | ^~~~~~~~~
p150.cpp:82:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:93:9: error: 'is_constant_evaluated' is not a member of 'std'
   93 | X7<std::is_constant_evaluated()> x7; // type X<true>
      |         ^~~~~~~~~~~~~~~~~~~~~
p150.cpp:93:9: error: 'is_constant_evaluated' is not a member of 'std'
p150.cpp:93:31: error: a function call cannot appear in a constant-expression
   93 | X7<std::is_constant_evaluated()> x7; // type X<true>
      |                               ^
p150.cpp:93:32: error: template argument 1 is invalid
   93 | X7<std::is_constant_evaluated()> x7; // type X<true>
      |                                ^
p150.cpp:95:21: error: 'is_constant_evaluated' is not a member of 'std'
   95 | const int a7 = std::is_constant_evaluated() ? y7 : 1; // dynamic initialization to 1
      |                     ^~~~~~~~~~~~~~~~~~~~~
p150.cpp:96:10: error: size of array 'z' is not an integral constant-expression
   96 | double z[a7]; // error: a is not usable
      |          ^~
p150.cpp:98:20: error: 'is_constant_evaluated' is not a member of 'std'
   98 | const int b = std::is_constant_evaluated() ? 2 : y7; // static initialization to 2
      |                    ^~~~~~~~~~~~~~~~~~~~~
p150.cpp:99:20: error: 'is_constant_evaluated' is not a member of 'std'
   99 | int c = y7 + (std::is_constant_evaluated() ? 2 : y7); // dynamic initialization to y+y
      |                    ^~~~~~~~~~~~~~~~~~~~~
p150.cpp:100:1: error: 'constexpr' does not name a type
  100 | constexpr int f7() {
      | ^~~~~~~~~
p150.cpp:100:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p150.cpp:106:9: error: 'f7' was not declared in this scope; did you mean 'y7'?
  106 | int p = f7(); // m is 13; initialized to 26
      |         ^~
      |         y7
p150.cpp:107:13: error: 'f7' was not declared in this scope; did you mean 'y7'?
  107 | int q = p + f7(); // m is 17 for this call; initialized to 56
      |             ^~
      |             y7
rm: cannot remove 'p150g': No such file or directory

$ g++ p150.cpp -std=2b -o p150g -I. -Wall
p150.cpp: In lambda function:
p150.cpp:23:21: error: lambda capture of 'n' is not a constant expression
   23 | constexpr int j = *&n; // error: &n would be an odr-use of n
      |                     ^
p150.cpp:23:21: note: because it is used as a glvalue
p150.cpp:22:15: warning: unused variable 'i' [-Wunused-variable]
   22 | constexpr int i = n; // OK, n is not odr-used here
      |               ^
p150.cpp:23:15: warning: unused variable 'j' [-Wunused-variable]
   23 | constexpr int j = *&n; // error: &n would be an odr-use of n
      |               ^
p150.cpp: At global scope:
p150.cpp:40:28:   in 'constexpr' expansion of 'A(0)'
p150.cpp:36:31: error: the value of 'x' is not usable in a constant expression
   36 | constexpr A(bool b) : m3(b?42:x) { }
      |                               ^
p150.cpp:34:5: note: 'int x' is not const
   34 | int x; // not constant
      |     ^
p150.cpp: In function 'constexpr int f1(int)':
p150.cpp:42:19: error: 'k' is not a constant expression
   42 | constexpr int x = k; // error: x is not initialized by a constant expression
      |                   ^
p150.cpp: In function 'constexpr int g3(int)':
p150.cpp:55:23:   in 'constexpr' expansion of 'incr(k)'
p150.cpp:55:25: error: 'k' is not a constant expression
   55 | constexpr int x = incr(k); // error: incr(k) is not a core constant expression
      |                         ^
p150.cpp: At global scope:
p150.cpp:75:9: error: 'alignas' argument has non-integral type 'const A4'
   75 | alignas(a) int n; // error: ambiguous conversion
      |         ^
p150.cpp:76:20: error: width of bit-field 'n' has non-integral type 'const A4'
   76 | struct B { int n : a; }; // error: ambiguous conversion
      |                    ^
p150.cpp:82:22: error: immediate evaluation returns address of immediate function 'consteval int f()'
   82 | constexpr auto e = g5(); // error: a pointer to an immediate function is
      |                    ~~^~
p150.cpp:96:10: error: size of array 'z' is not an integral constant-expression
   96 | double z[a7]; // error: a is not usable
      |          ^~
p150.cpp:82:16: warning: 'e' defined but not used [-Wunused-variable]
   82 | constexpr auto e = g5(); // error: a pointer to an immediate function is
      |                ^
```

## 検討事項(agenda)
コンパイルエラーの理由を解説する。

<|--コンパイルエラーを取るか、コンパイルエラーの理由を解説する。-->

# 参考資料(reference)

typedef は C++11 ではオワコン

https://qiita.com/Linda_pp/items/44a67c64c14cba00eef1

C99からC++14を駆け抜けるC++講座

https://qiita.com/yumetodo/items/e49a673afd9a3ecb81a8

## 自己参照(self reference)

C++ Error Message Collection(1)does not name a type, 11 articles

https://qiita.com/kaizen_nagoya/items/acb9f1a9b5aad6df06bd

dockerにclang

https://qiita.com/kaizen_nagoya/items/8829ffeee397eda50e80

docker gnu(gcc/g++) and llvm(clang/clang++)

https://qiita.com/drafts/059874ea39c4de64c0f7

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)

https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da

Compare the contents of C++N4910:2022, C++N4741:2018 and C++N4606:2015

https://qiita.com/kaizen_nagoya/items/483246d40f98abff7ded

C++ sample list

https://qiita.com/kaizen_nagoya/items/54ad75b73825b7c04f86


clang++, g++コンパイルエラー方針の違いの例

https://qiita.com/kaizen_nagoya/items/ea6e5009fe126d270a82


C++N4606 Working Draft 2016, ISO/IEC 14882, C++ standardのコード断片をコンパイルするためにしていること
https://qiita.com/kaizen_nagoya/items/a8d7ee2f2e29e76c19c1

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da

Clang/Clang++(LLVM) gcc/g++(GNU) コンパイラ警告等比較
https://qiita.com/kaizen_nagoya/items/9a82b958cc3aeef0403f

C++2003とC++2017でコンパイルエラーになるならない事例集
https://qiita.com/kaizen_nagoya/items/a13ea3823441c430edff

Qiitaに投稿するCのStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d

cpprefjpのdecltypeをコンパイル試験
https://qiita.com/kaizen_nagoya/items/090909af702f0d5d8a67

MISRA C++ 5-0-16
https://qiita.com/kaizen_nagoya/items/7df2d4e05db724752a74

C++ Templates Part1 BASICS Chapter 3. Class Templates 3.2 Use of Class Template Stack stack1test.cpp
https://qiita.com/kaizen_nagoya/items/cd5fc49106fad5a4e9ed

ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)
https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1

C言語（C++)に対する誤解、曲解、無理解、爽快。
https://qiita.com/kaizen_nagoya/items/3f3992c9722c1cee2e3a

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9

'wchar.h' file not found で困った clang++ macOS
https://qiita.com/kaizen_nagoya/items/de15cd46d657517fac11

Open POSIX Test Suiteの使い方を調べはじめました
https://qiita.com/kaizen_nagoya/items/644d5e407f5faf96e6dc

MISRA-C 2012 Referenceに掲載している文献の入手可能性を確認
https://qiita.com/kaizen_nagoya/items/96dc8b125e462d5575bb

どうやって MISRA Example Suiteをコンパイルするか
https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00

MISRA C まとめ #include <misra_c.h>
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9

「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671


 ＜この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。＞

# 文書履歴(document history)
ver. 0.01 初稿 　20220625