4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AUTOSAR CountdownAdvent Calendar 2022

Day 2

cpprefjpのdecltypeをコンパイル試験 C++(15)

Last updated at Posted at 2018-04-30

最近、何かとお世話になっているcpprefjp。

C++でわからないことがあると検索しては記録している。
https://researchmap.jp/joub9b3my-1797580/#_1797580

一番お世話になっているのがcpprefjp
https://cpprefjp.github.io/lang/cpp11/decltype.html

同じ言葉を二度検索したら、コンパイル試験をすることにした。
ひとまずhosted環境で試験、該当する関数、変数がfreestanding環境でも実現可能な場合はfreestanding環境でも試験。

一例づつコンパイルするのが面倒。変数をぶつからないように変更してコンパイル。

clang++, g++で-std=c++03, -std=c++11, -std=c++17の3種類づつコンパイル。

clang++ -std=c++17だけコンパイルが通った。

編纂器(Compiler)

clang++ --version

clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.4.0

g++-7 --version

g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.

算譜(source code)

decltype.cpp
#include <iostream>
#include <utility> // for sample7

//decltype at cpprefjp(c)
//https://cpprefjp.github.io/lang/cpp11/decltype.html

//C++2003
//  template <class Func, class T>
//  ??? trace(Func f, T t) { std::cout << "Calling f"; return f(t); }
//C++2011
//  template <class Func, class T>
//  auto trace(Func f, T t) -> decltype(f(t)) { std::cout << "Calling f"; return f(t); }
//C++2014
//  template <class Func, class T>
//  decltype(auto) trace(Func f, T t) { std::cout << "Calling f"; return f(t); }

//sample1
int i = 0;
decltype(i) j = 0;                      // j は int 型
decltype(i)* p = &i;                    // p は int* 型
decltype((i)) k = i;                    // k は int& 型(変数名 i の周りの余分な丸括弧に注意)

template<typename T, typename U>
auto add(const T& lhs, const U& rhs)
-> decltype(lhs + rhs);               // add の戻り値型は lhs + rhs の式の型

struct S {
  using U = decltype(add('a', 'b'));    // S::U は int 型の別名
} s;

decltype(s)::U l{};                     // l は S::U 型(つまり int 型)

//sample2
template<typename T, typename U>
auto add(const T& lhs, const U& rhs)
-> decltype(lhs + rhs)                // add の戻り値型は lhs + rhs の式の型
{
  return lhs + rhs;
}

//sampl4 change S to S2
struct S2 {
  int i = 42;
};

//sample5 change S to S3
struct S3 {
  S3() {
    std::cout << "S3()\n";
  }
  ~S3() {
    std::cout << "~S3()\n";
  }
};

S3 f();

//sample6 change S to S4, s to s2
struct S4 {
  int i;
  S4(int i) : i(i) {}
  operator decltype(i)() {
    return i;  // int 型への変換演算子
  }
};

//sample7 cange S to S5
template<typename T>
auto d(T&& x)
{
  return x + x;
}

struct S5 {
  static constexpr int g = 20;
};

constexpr int S5::g;

int main()
{
  std::cout <<std::endl<<"sample7"<<std::endl;
  auto l = [](auto&& x) {
    std::cout << "start\n";
    auto ret = d(std::forward<decltype(x)>(x));     // x の型のままで転送
    std::cout << "end\n";
    return ret;
  };
  std::cout << l(S5::g) << '\n';

//sample6
  S4 s2(42);
  std::cout <<std::endl<<"sample6"<<std::endl;
  std::cout << s2 << '\n';
//sample5
  std::cout <<std::endl<<"sample5"<<std::endl;
  std::cout << "allocate\n";
  void* p = ::operator new(sizeof(f()));

  std::cout << "construct\n";
  ::new(p) decltype(f());                       // 配置 new で p の指すメモリに S 型のオブジェクトを構築

  std::cout << "destruct\n";
  auto sp = static_cast<decltype(f())*>(p);     // デストラクタ呼び出しのため、S 型へのポインタにキャスト
  sp->~decltype(f())();                         // 明示的デストラクタ呼び出しで sp の指すメモリの S 型オブジェクトを破棄

  std::cout << "deallocate\n";
  ::operator delete(p);

//sample4 change S to S2
  S2 s;
  auto mp = &decltype(s)::i;             // mp の型は int S::* 型(S の int 型のメンバへのポインタ)
  std::cout <<std::endl<<"sample4"<<std::endl;
  std::cout << s.*mp << '\n';

//sample3
  int i = 10;
  decltype(i) j = i;                    // j は int 型
  decltype((i)) k = i;                  // k は int& 型(i は lvalue で丸括弧が付いているので)

  i = 42;
  std::cout <<std::endl<<"sample3"<<std::endl;
  std::cout << j << ", " << k << '\n';

//sample2
  auto r = add(1, 2.0F);                // r の型は float 型
  std::cout <<std::endl<<"sample2"<<std::endl;
  std::cout << std::fixed << r << '\n';
}
cppall.sh
$ ./cppall.sh decltype
$ clang++ decltype.cpp -std=c++03 -Wall
decltype.cpp:24:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto add(const T& lhs, const U& rhs)
^
decltype.cpp:24:1: error: 'auto' not allowed in function return type
auto add(const T& lhs, const U& rhs)
^~~~
decltype.cpp:24:37: error: expected ';' at end of declaration
auto add(const T& lhs, const U& rhs)
                                    ^
                                    ;
decltype.cpp:25:3: error: cannot use arrow operator on a type
  -> decltype(lhs + rhs);               // add の戻り値型は lhs + rhs の式の型
  ^
decltype.cpp:28:13: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
  using U = decltype(add('a', 'b'));    // S::U は int 型の別名
            ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/__config:821:25: note: expanded from macro 'decltype'
#  define decltype(__x) __decltype(__x)
                        ^
decltype.cpp:28:22: error: no matching function for call to 'add'
  using U = decltype(add('a', 'b'));    // S::U は int 型の別名
                     ^~~
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/__config:821:36: note: expanded from macro 'decltype'
#  define decltype(__x) __decltype(__x)
                                   ^~~
decltype.cpp:31:14: error: no type named 'U' in 'S'
decltype(s)::U l{};                     // l は S::U 型(つまり int 型)  
~~~~~~~~~~~~~^
decltype.cpp:31:17: error: expected ';' after top level declarator
decltype(s)::U l{};                     // l は S::U 型(つまり int 型)  
                ^
                ;
decltype.cpp:35:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto add(const T& lhs, const U& rhs)
^
decltype.cpp:35:1: error: 'auto' not allowed in function return type
auto add(const T& lhs, const U& rhs)
^~~~
decltype.cpp:35:37: error: expected ';' at end of declaration
auto add(const T& lhs, const U& rhs)
                                    ^
                                    ;
decltype.cpp:36:3: error: cannot use arrow operator on a type
  -> decltype(lhs + rhs)                // add の戻り値型は lhs + rhs の式の型
  ^
decltype.cpp:43:9: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
  int i = 42;
        ^
decltype.cpp:58:21: error: invalid use of non-static data member 'i'
  operator decltype(i)() { return i; }        // int 型への変換演算子
                    ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/__config:821:36: note: expanded from macro 'decltype'
#  define decltype(__x) __decltype(__x)
                                   ^~~
decltype.cpp:63:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto d(T&& x)
^
decltype.cpp:63:9: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
auto d(T&& x)
        ^
decltype.cpp:63:1: error: 'auto' not allowed in function return type
auto d(T&& x)
^~~~
decltype.cpp:69:10: error: unknown type name 'constexpr'
  static constexpr int g = 20;
         ^
decltype.cpp:69:20: error: expected member name or ';' after declaration specifiers
  static constexpr int g = 20;
  ~~~~~~~~~~~~~~~~ ^
decltype.cpp:72:1: error: unknown type name 'constexpr'
constexpr int S5::g;
^
decltype.cpp:72:11: error: expected unqualified-id
constexpr int S5::g;
          ^
decltype.cpp:77:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  auto l = [](auto&& x) {
  ^
decltype.cpp:77:12: error: expected expression
  auto l = [](auto&& x) {
           ^
decltype.cpp:83:22: error: no member named 'g' in 'S5'
  std::cout << l(S5::g) << '\n';
                 ~~~~^
decltype.cpp:88:13: error: invalid operands to binary expression ('std::__1::ostream' (aka 'basic_ostream<char>') and 'S4')
  std::cout << s2 << '\n';
  ~~~~~~~~~ ^  ~~
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:218:20: note: candidate function not viable: no known conversion from 'S4' to 'const void *' for 1st
      argument; take the address of the argument with &
    basic_ostream& operator<<(const void* __p);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:194:20: note: candidate function not viable: no known conversion from 'S4' to
      'std::__1::basic_ostream<char> &(*)(std::__1::basic_ostream<char> &)' for 1st argument
    basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:198:20: note: candidate function not viable: no known conversion from 'S4' to
      'basic_ios<std::__1::basic_ostream<char, std::__1::char_traits<char> >::char_type, std::__1::basic_ostream<char, std::__1::char_traits<char>
      >::traits_type> &(*)(basic_ios<std::__1::basic_ostream<char, std::__1::char_traits<char> >::char_type, std::__1::basic_ostream<char,
      std::__1::char_traits<char> >::traits_type> &)' (aka 'basic_ios<char, std::__1::char_traits<char> > &(*)(basic_ios<char, std::__1::char_traits<char> >
      &)') for 1st argument
    basic_ostream& operator<<(basic_ios<char_type, traits_type>&
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:203:20: note: candidate function not viable: no known conversion from 'S4' to
      'std::__1::ios_base &(*)(std::__1::ios_base &)' for 1st argument
    basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:206:20: note: candidate function not viable: no known conversion from 'S4' to 'bool' for 1st argument
    basic_ostream& operator<<(bool __n);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:207:20: note: candidate function not viable: no known conversion from 'S4' to 'short' for 1st argument
    basic_ostream& operator<<(short __n);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:208:20: note: candidate function not viable: no known conversion from 'S4' to 'unsigned short' for 1st
      argument
    basic_ostream& operator<<(unsigned short __n);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:209:20: note: candidate function not viable: no known conversion from 'S4' to 'int' for 1st argument
    basic_ostream& operator<<(int __n);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:210:20: note: candidate function not viable: no known conversion from 'S4' to 'unsigned int' for 1st
      argument
    basic_ostream& operator<<(unsigned int __n);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:211:20: note: candidate function not viable: no known conversion from 'S4' to 'long' for 1st argument
    basic_ostream& operator<<(long __n);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:212:20: note: candidate function not viable: no known conversion from 'S4' to 'unsigned long' for 1st
      argument
    basic_ostream& operator<<(unsigned long __n);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:213:20: note: candidate function not viable: no known conversion from 'S4' to 'long long' for 1st
      argument
    basic_ostream& operator<<(long long __n);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:214:20: note: candidate function not viable: no known conversion from 'S4' to 'unsigned long long' for
      1st argument
    basic_ostream& operator<<(unsigned long long __n);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:215:20: note: candidate function not viable: no known conversion from 'S4' to 'float' for 1st argument
    basic_ostream& operator<<(float __f);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:216:20: note: candidate function not viable: no known conversion from 'S4' to 'double' for 1st argument
    basic_ostream& operator<<(double __f);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:217:20: note: candidate function not viable: no known conversion from 'S4' to 'long double' for 1st
      argument
    basic_ostream& operator<<(long double __f);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:219:20: note: candidate function not viable: no known conversion from 'S4' to
      'basic_streambuf<std::__1::basic_ostream<char, std::__1::char_traits<char> >::char_type, std::__1::basic_ostream<char, std::__1::char_traits<char>
      >::traits_type> *' (aka 'basic_streambuf<char, std::__1::char_traits<char> > *') for 1st argument
    basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
                   ^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:755:1: note: candidate function not viable: no known conversion from 'S4' to 'char' for 2nd argument
operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:788:1: note: candidate function not viable: no known conversion from 'S4' to 'char' for 2nd argument
operator<<(basic_ostream<char, _Traits>& __os, char __c)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:795:1: note: candidate function not viable: no known conversion from 'S4' to 'signed char' for 2nd
      argument
operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:802:1: note: candidate function not viable: no known conversion from 'S4' to 'unsigned char' for 2nd
      argument
operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:816:1: note: candidate function not viable: no known conversion from 'S4' to 'const char *' for 2nd
      argument
operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:862:1: note: candidate function not viable: no known conversion from 'S4' to 'const char *' for 2nd
      argument
operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:869:1: note: candidate function not viable: no known conversion from 'S4' to 'const signed char *' for
      2nd argument
operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:877:1: note: candidate function not viable: no known conversion from 'S4' to 'const unsigned char *' for
      2nd argument
operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:1061:1: note: candidate function not viable: no known conversion from 'S4' to
      'const std::__1::error_code' for 2nd argument
operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:748:1: note: candidate template ignored: deduced conflicting types for parameter '_CharT'
      ('char' vs. 'S4')
operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:809:1: note: candidate template ignored: could not match 'const _CharT *' against 'S4'
operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:1044:1: note: candidate template ignored: could not match 'basic_string<type-parameter-0-0,
      type-parameter-0-1, type-parameter-0-2>' against 'S4'
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:1052:1: note: candidate template ignored: could not match 'basic_string_view<type-parameter-0-0,
      type-parameter-0-1>' against 'S4'
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:1069:1: note: candidate template ignored: could not match 'shared_ptr<type-parameter-0-2>' against 'S4'
operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
^
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/ostream:1090:1: note: candidate template ignored: could not match 'bitset<_Size>' against 'S4'
operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
^
decltype.cpp:98:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  auto sp = static_cast<decltype(f())*>(p);     // デストラクタ呼び出しのため、S 型へのポインタにキャスト
  ^
decltype.cpp:106:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  auto mp = &decltype(s)::i;             // mp の型は int S::* 型(S の int 型のメンバへのポインタ)
  ^
decltype.cpp:120:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  auto r = add(1, 2.0F);                // r の型は float 型
  ^
decltype.cpp:120:12: error: no matching function for call to 'add'
  auto r = add(1, 2.0F);                // r の型は float 型
           ^~~
10 warnings and 19 errors generated.
$ clang++ decltype.cpp -std=c++11 -Wall
decltype.cpp:63:1: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
auto d(T&& x)
^
decltype.cpp:77:15: error: 'auto' not allowed in lambda parameter
  auto l = [](auto&& x) {
              ^~~~
decltype.cpp:83:16: error: no matching function for call to object of type '(lambda at decltype.cpp:77:12)'
  std::cout << l(S5::g) << '\n';
               ^
decltype.cpp:77:12: note: candidate function not viable: 1st argument ('const int') would lose const qualifier
  auto l = [](auto&& x) {
           ^
decltype.cpp:77:12: note: conversion candidate of type 'void (*)(int &&)'
3 errors generated.

$ clang++ decltype.cpp -std=c++17 -Wall

sample7
start
end
40

sample6
42

sample5
allocate
construct
S3()
destruct
~S3()
deallocate

sample4
42

sample3
10, 42

sample2
3.000000

$ g++-7 decltype.cpp -std=c++03  -Wall
decltype.cpp:19:1: warning: identifier 'decltype' is a keyword in C++11 [-Wc++11-compat]
 decltype(i) j = 0;                      // j は int 型
 ^~~~~~~~
decltype.cpp:69:3: warning: identifier 'constexpr' is a keyword in C++11 [-Wc++11-compat]
   static constexpr int g = 20;
   ^~~~~~
decltype.cpp:19:9: error: expected constructor, destructor, or type conversion before '(' token
 decltype(i) j = 0;                      // j は int 型
         ^
decltype.cpp:20:9: error: expected constructor, destructor, or type conversion before '(' token
 decltype(i)* p = &i;                    // p は int*         ^
decltype.cpp:21:9: error: expected constructor, destructor, or type conversion before '(' token
 decltype((i)) k = i;                    // k は int& 型(変数名 i の周りの余分な丸括弧に注意)
         ^
decltype.cpp:24:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
 auto add(const T& lhs, const U& rhs)
 ^~~~
decltype.cpp:25:6: error: expected type-specifier before 'decltype'
   -> decltype(lhs + rhs);               // add の戻り値型は lhs + rhs の式の型
      ^~~~~~~~
decltype.cpp:25:6: error: expected initializer before 'decltype'
decltype.cpp:28:9: error: expected nested-name-specifier before 'U'
   using U = decltype(add('a', 'b'));    // S::U は int 型の別名
         ^
decltype.cpp:31:9: error: expected constructor, destructor, or type conversion before '(' token
 decltype(s)::U l{};                     // l は S::U 型(つまり int 型)
         ^
decltype.cpp:35:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
 auto add(const T& lhs, const U& rhs)
 ^~~~
decltype.cpp:36:6: error: expected type-specifier before 'decltype'
   -> decltype(lhs + rhs)                // add の戻り値型は lhs + rhs の式の型
      ^~~~~~~~
decltype.cpp:36:6: error: expected initializer before 'decltype'
decltype.cpp:43:11: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
   int i = 42;
           ^~
decltype.cpp:58:12: error: expected type-specifier before 'decltype'
   operator decltype(i)() { return i; }        // int 型への変換演算子
            ^~~~~~~~
decltype.cpp:63:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
 auto d(T&& x)
 ^~~~
decltype.cpp:63:9: error: expected ',' or '...' before '&&' token
 auto d(T&& x)
         ^~
decltype.cpp:63:13: error: ISO C++ forbids declaration of 'd' with no type [-fpermissive]
 auto d(T&& x)
             ^
decltype.cpp:63:13: error: top-level declaration of 'd' specifies 'auto'
decltype.cpp:63:13: error: storage class 'auto' invalid for function 'd'
decltype.cpp: In function 'int d(T)':
decltype.cpp:65:10: error: 'x' was not declared in this scope
   return x + x;
          ^
decltype.cpp: At global scope:
decltype.cpp:69:10: error: 'constexpr' does not name a type
   static constexpr int g = 20;
          ^~~~~~~~~
decltype.cpp:69:10: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
decltype.cpp:72:1: error: 'constexpr' does not name a type
 constexpr int S5::g;
 ^~~~~~~~~
decltype.cpp:72:1: note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11
decltype.cpp: In function 'int main()':
decltype.cpp:77:3: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   auto l = [](auto&& x) {
   ^~~~
decltype.cpp:77:8: error: 'l' does not name a type
   auto l = [](auto&& x) {
        ^
decltype.cpp:83:22: error: 'g' is not a member of 'S5'
   std::cout << l(S5::g) << '\n';
                      ^
decltype.cpp:83:16: error: 'l' was not declared in this scope
   std::cout << l(S5::g) << '\n';
                ^
decltype.cpp:88:13: error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'S4')
   std::cout << s2 << '\n';
   ~~~~~~~~~~^~~~~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:108:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(__ostream_type& (*__pf)(__ostream_type&))
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:108:7: note:   no known conversion for argument 1 from 'S4' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:117:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
       operator<<(__ios_type& (*__pf)(__ios_type&))
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:117:7: note:   no known conversion for argument 1 from 'S4' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:127:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(ios_base& (*__pf) (ios_base&))
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:127:7: note:   no known conversion for argument 1 from 'S4' to 'std::ios_base& (*)(std::ios_base&)'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:166:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(long __n)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:166:7: note:   no known conversion for argument 1 from 'S4' to 'long int'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:170:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(unsigned long __n)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:170:7: note:   no known conversion for argument 1 from 'S4' to 'long unsigned int'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:174:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(bool __n)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:174:7: note:   no known conversion for argument 1 from 'S4' to 'bool'
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:693:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ostream.tcc:91:5: note: candidate: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]
     basic_ostream<_CharT, _Traits>::
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ostream.tcc:91:5: note:   no known conversion for argument 1 from 'S4' to 'short int'
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:181:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(unsigned short __n)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:181:7: note:   no known conversion for argument 1 from 'S4' to 'short unsigned int'
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:693:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ostream.tcc:105:5: note: candidate: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]
     basic_ostream<_CharT, _Traits>::
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ostream.tcc:105:5: note:   no known conversion for argument 1 from 'S4' to 'int'
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:192:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(unsigned int __n)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:192:7: note:   no known conversion for argument 1 from 'S4' to 'unsigned int'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:201:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(long long __n)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:201:7: note:   no known conversion for argument 1 from 'S4' to 'long long int'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:205:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(unsigned long long __n)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:205:7: note:   no known conversion for argument 1 from 'S4' to 'long long unsigned int'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:220:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(double __f)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:220:7: note:   no known conversion for argument 1 from 'S4' to 'double'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:224:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(float __f)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:224:7: note:   no known conversion for argument 1 from 'S4' to 'float'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:232:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(long double __f)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:232:7: note:   no known conversion for argument 1 from 'S4' to 'long double'
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:245:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(const void* __p)
       ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:245:7: note:   no known conversion for argument 1 from 'S4' to 'const void*'
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:693:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ostream.tcc:119:5: note: candidate: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
     basic_ostream<_CharT, _Traits>::
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ostream.tcc:119:5: note:   no known conversion for argument 1 from 'S4' to 'std::basic_ostream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}'
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:574:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
     operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:574:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   cannot convert 's2' (type 'S4') to type 'const unsigned char*'
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:569:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
     operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:569:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   cannot convert 's2' (type 'S4') to type 'const signed char*'
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:556:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:556:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   cannot convert 's2' (type 'S4') to type 'const char*'
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:693:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ostream.tcc:321:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ostream.tcc:321:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   cannot convert 's2' (type 'S4') to type 'const char*'
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:539:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:539:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   mismatched types 'const _CharT*' and 'S4'
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:519:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:519:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   cannot convert 's2' (type 'S4') to type 'unsigned char'
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:514:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:514:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   cannot convert 's2' (type 'S4') to type 'signed char'
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:508:5: note: candidate: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
     operator<<(basic_ostream<char, _Traits>& __out, char __c)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:508:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   cannot convert 's2' (type 'S4') to type 'char'
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:502:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:502:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   cannot convert 's2' (type 'S4') to type 'char'
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39:0,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:497:5: note: candidate: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:497:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   deduced conflicting types for parameter '_CharT' ('char' and 'S4')
   std::cout << s2 << '\n';
                ^~
In file included from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/string:52:0,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/locale_classes.h:40,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/ios_base.h:41,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ios:42,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/ostream:38,
                 from /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/iostream:39,
                 from decltype.cpp:1:
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/basic_string.h:6272:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator<<(basic_ostream<_CharT, _Traits>& __os,
     ^~~~~~~~
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/basic_string.h:6272:5: note:   template argument deduction/substitution failed:
decltype.cpp:88:16: note:   'S4' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>'
   std::cout << s2 << '\n';
                ^~
decltype.cpp:95:12: error: expected type-specifier before 'decltype'
   ::new(p) decltype(f());                       // 配置 new で p の指すメモリに S 型のオブジェクトを構築
            ^~~~~~~~
decltype.cpp:98:3: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   auto sp = static_cast<decltype(f())*>(p);     // デストラクタ呼び出しのため、S 型へのポインタにキャスト
   ^~~~
decltype.cpp:98:8: error: 'sp' does not name a type; did you mean 'p'?
   auto sp = static_cast<decltype(f())*>(p);     // デストラクタ呼び出しのため、S 型へのポインタにキャスト
        ^~
        p
decltype.cpp:99:3: error: 'sp' was not declared in this scope
   sp->~decltype(f())();                         // 明示的デストラクタ呼び出しで sp の指すメモリの S 型オブジェクトを破棄
   ^~
decltype.cpp:99:3: note: suggested alternative: 'p'
   sp->~decltype(f())();                         // 明示的デストラクタ呼び出しで sp の指すメモリの S 型オブジェクトを破棄
   ^~
   p
decltype.cpp:99:16: error: expected class-name before '(' token
   sp->~decltype(f())();                         // 明示的デストラクタ呼び出しで sp の指すメモリの S 型オブジェクトを破棄
                ^
decltype.cpp:106:3: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   auto mp = &decltype(s)::i;             // mp の型は int S::* 型(S の int 型のメンバへのポインタ)
   ^~~~
decltype.cpp:106:8: error: 'mp' does not name a type; did you mean 'p'?
   auto mp = &decltype(s)::i;             // mp の型は int S::* 型(S の int 型のメンバへのポインタ)
        ^~
        p
decltype.cpp:108:19: error: 'mp' was not declared in this scope
   std::cout << s.*mp << '\n';
                   ^~
decltype.cpp:108:19: note: suggested alternative: 'p'
   std::cout << s.*mp << '\n';
                   ^~
                   p
decltype.cpp:112:3: error: 'decltype' was not declared in this scope
   decltype(i) j = i;                    // j は int 型
   ^~~~~~~~
decltype.cpp:112:3: note: suggested alternative: 'wctype'
   decltype(i) j = i;                    // j は int 型
   ^~~~~~~~
   wctype
decltype.cpp:117:16: error: 'j' was not declared in this scope
   std::cout << j << ", " << k << '\n';
                ^
decltype.cpp:117:29: error: 'k' was not declared in this scope
   std::cout << j << ", " << k << '\n';
                             ^
decltype.cpp:120:3: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   auto r = add(1, 2.0F);                // r の型は float 型
   ^~~~
decltype.cpp:120:8: error: 'r' does not name a type
   auto r = add(1, 2.0F);                // r の型は float 型
        ^
decltype.cpp:122:30: error: 'r' was not declared in this scope
   std::cout << std::fixed << r << '\n';
                              ^

$ g++-7 decltype.cpp -std=c++11  -Wall
decltype.cpp:63:13: error: 'd' function uses 'auto' type specifier without trailing return type
 auto d(T&& x)
             ^
decltype.cpp:63:13: note: deduced return type only available with -std=c++14 or -std=gnu++14
decltype.cpp: In function 'int main()':
decltype.cpp:77:15: error: use of 'auto' in lambda parameter declaration only available with -std=c++14 or -std=gnu++14
   auto l = [](auto&& x) {
               ^~~~
decltype.cpp:83:23: error: no match for call to '(main()::<lambda(int&&)>) (const int&)'
   std::cout << l(S5::g) << '\n';
                       ^
decltype.cpp:83:23: note: candidate: int (*)(int&&) <conversion>
decltype.cpp:83:23: note:   conversion of argument 2 would be ill-formed:
decltype.cpp:83:23: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'const int'
decltype.cpp:77:23: note: candidate: main()::<lambda(int&&)> <near match>
   auto l = [](auto&& x) {
                       ^
decltype.cpp:77:23: note:   conversion of argument 1 would be ill-formed:
decltype.cpp:83:23: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'const int'
   std::cout << l(S5::g) << '\n';
                       ^
decltype.cpp:99:8: error: expected class-name before 'decltype'
   sp->~decltype(f())();                         // 明示的デストラクタ呼び出しで sp の指すメモリの S 型オブジェクトを破棄
        ^~~~~~~~

$ g++-7 decltype.cpp -std=c++17  -Wall
decltype.cpp: In function 'int main()':
decltype.cpp:99:8: error: expected class-name before 'decltype'
   sp->~decltype(f())();                         // 明示的デストラクタ呼び出しで sp の指すメモリの S 型オブジェクトを破棄
        ^~~~~~~~

検討事項(agenda)

コンパイルエラーの分類
sample1が出力がない。役に立つまたは意味のある出力の作成。

参考資料(reference)

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

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

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

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

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

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

C++N4606, 2016 Standard Working Draft on ISO/IEC 14882(1) Exsample code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43

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

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

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

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

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

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

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

コンパイルエラー記録理由

Verilog HDLだとコンパイルエラーをネットで検索すると必要な情報にすぐたどり着くことが多い。
C, C++ネットで検索しても必要な情報にたどり着かない。やれヒットしたと思ったら、自分がうまくいかずに数年前に記録したサイトだけということがしばしば。

コンパイルエラーと、コンパイルがうまく行った事例を併記することにより、検索して解決する確率を高めるのが目的。

自己参照

C++ Support(0) 
https://qiita.com/kaizen_nagoya/items/8720d26f762369a80514

Coding Rules(0) C Secure , MISRA and so on
https://qiita.com/kaizen_nagoya/items/400725644a8a0e90fbb0

Ethernet 記事一覧 Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794

Wireshark 一覧 wireshark(0)、Ethernet(48)
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0

線網(Wi-Fi)空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001

OSEK OS設計の基礎 OSEK(100)
https://qiita.com/kaizen_nagoya/items/7528a22a14242d2d58a3

Error一覧(C/C++, python, bash...) Error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8

なぜdockerで機械学習するか 書籍・ソース一覧作成中 (目標100)
https://qiita.com/kaizen_nagoya/items/ddd12477544bf5ba85e2

言語処理100本ノックをdockerで。python覚えるのに最適。:10+12
https://qiita.com/kaizen_nagoya/items/7e7eb7c543e0c18438c4

プログラムちょい替え(0)一覧:4件
https://qiita.com/kaizen_nagoya/items/296d87ef4bfd516bc394

TOPPERSまとめ #名古屋のIoTは名古屋のOSで
https://qiita.com/kaizen_nagoya/items/9026c049cb0309b9d451

docker(0) 資料集
https://qiita.com/kaizen_nagoya/items/45699eefd62677f69c1d

Qiita-dockerお宝鑑定団
https://qiita.com/kaizen_nagoya/items/509e125263559b5aed5b

The C++ Standard Library: clang++とg++でコンパイルしてみた(まとめ):14件
https://qiita.com/kaizen_nagoya/items/9bdfaa392443d13e5759

C++17 - The Complete Guide clang++とg++でコンパイルしてみた(まとめ):4件
https://qiita.com/kaizen_nagoya/items/c000f307e642990781e1

C++N3242, 2011, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318

C++N4606 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/

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

C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list
https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91

Autosar Guidelines C++14 example code compile list(1-169)
https://qiita.com/kaizen_nagoya/items/8ccbf6675c3494d57a76

プログラマによる、プログラマのための、統計と確率のプログラミングとその後 統計と確率一覧(0)
https://qiita.com/kaizen_nagoya/items/6e9897eb641268766909

一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
This article is an individual impression based on the individual's experience. It has nothing to do with the organization or business to which I currently belong.

文書履歴(document history)

ver. 0.10 初稿 20180430
ver. 0.11 compile and goを別の結果と差し替え. 20180430
ver. 0.12 ありがとう追記 20230413

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

4
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?