0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

20.2.7.2 Uses-allocator construction [allocator.uses.construction] C++N4910:2022 (429) p589.cpp

Posted at

はじめに(Introduction)

N4910 Working Draft, Standard for Programming Language C++

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++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。

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

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の2種類
でコンパイルし、

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

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

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

C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list

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++

編纂器(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.

20.2.7.2 Uses-allocator construction [allocator.uses.construction] C++N4910:2022 (429) p589.cpp

算譜(source code)

p589.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 * n4910 = "20.2.7.2 Uses-allocator construction [allocator.uses.construction] C++N4910:2022 (429) p589.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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <coroutine>
#include <vector>
#include <complex>
#include <map>
#include <atomic>
#include <unordered_map>
#include <typeinfo>

using namespace std;

// Example 1
template<class T, class Alloc, class... Args>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
        Args&&... args) noexcept;
// Constraints: T is not a specialization of pair. Returns: A tuple value determined as follows:
// - If uses_allocator_v<T, Alloc> is false and is_constructible_v<T, Args...> is true, re- turn forward_as_tuple(std::forward<Args>(args)...).
// - Otherwise, if uses_allocator_v<T, Alloc> is true and is_constructible_v<T, allocator_- arg_t, const Alloc&, Args...> is true, return
tuple<allocator_arg_t, const Alloc&, Args&&...>(
    allocator_arg, alloc, std::forward<Args>(args)...)
// - Otherwise, if uses_allocator_v<T, Alloc> is true and is_constructible_v<T, Args..., const Alloc&> is true, return forward_as_tuple(std::forward<Args>(args)..., alloc).
// - Otherwise, the program is ill-formed.
// [Note 2: This definition prevents a silent failure to pass the allocator to a constructor of a type for which uses_allocator_v<T, Alloc> is true.
// Constraints: T is a specialization of pair. Effects: Equivalent to:
return uses_allocator_construction_args<T>(alloc, piecewise_construct,
tuple<> {}, tuple<> {});
template<class T, class Alloc, class Tuple1, class Tuple2>
constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
        Tuple1&& x, Tuple2&& y) noexcept;
// Constraints: T is a specialization of pair.
// Effects: For T specified as pair<T1, T2>, equivalent to:
return make_tuple(
           piecewise_construct,
apply([&alloc](auto&&... args1) {
    return uses_allocator_construction_args<T1>(
               alloc, std::forward<decltype(args1)>(args1)...);
}, std::forward<Tuple1>(x)),
apply([&alloc](auto&&... args2) {
    return uses_allocator_construction_args<T2>(
               alloc, std::forward<decltype(args2)>(args2)...);
}, std::forward<Tuple2>(y)));
template<class T, class Alloc>
constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept;
template<class T, class Alloc, class U, class V>
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
// Constraints: T is a specialization of pair. Effects: Equivalent to:
        return uses_allocator_construction_args<T>(alloc, piecewise_construct,
                forward_as_tuple(std::forward<U>(u)),
                forward_as_tuple(std::forward<V>(v)));
        template<class T, class Alloc, class U, class V>
        constexpr auto uses_allocator_construction_args(const Alloc& alloc,
                pair<U, V>& pr) noexcept;
        template<class T, class Alloc, class U, class V>
        constexpr auto uses_allocator_construction_args(const Alloc& alloc,
// Constraints: T is a specialization of pair. Effects: Equivalent to:
                return uses_allocator_construction_args<T>(alloc, piecewise_construct,
                        forward_as_tuple(pr.first),
                        forward_as_tuple(pr.second));
                template<class T, class Alloc, class U, class V>
                constexpr auto uses_allocator_construction_args(const Alloc& alloc,
                        pair<U, V>&& pr) noexcept;
                constexpr auto uses_allocator_construction_args(const Alloc& alloc,
                        U&& u, V&& v) noexcept;
                template<class T, class Alloc, class U, class V>
                const pair<U, V>& pr) noexcept;
// Constraints: T is a specialization of pair. Effects: Equivalent to:
        return uses_allocator_construction_args<T>(alloc, piecewise_construct,
                forward_as_tuple(get<0>(std::move(pr))),
                forward_as_tuple(get<1>(std::move(pr))));
        template<class T, class Alloc, class U>
        constexpr auto uses_allocator_construction_args(const Alloc& alloc, U&& u) noexcept;
        template<class T, class Alloc, class... Args>
        constexpr T make_obj_using_allocator(const Alloc& alloc, Args&&... args);
// Effects: Equivalent to:
        return make_from_tuple<T>(uses_allocator_construction_args<T>(
                                      alloc, std::forward<Args>(args)...));
        template<class T, class Alloc, class... Args>
        constexpr T* uninitialized_construct_using_allocator(T* p, const Alloc& alloc, Args&&... args);
// Effects: Equivalent to:
return apply([&]<class... U>(U&&... xs) {
    return construct_at(p, std::forward<U>(xs)...);
}, uses_allocator_construction_args<T>(alloc, std::forward<Args>(args)...));
const pair<U, V>&& pr) noexcept;
// Let FUN be the function template: template<class A, class B>
void FUN(const pair<A, B>&);
// Constraints: T is a specialization of pair, and the expression FUN (u) is not well-formed when considered as an unevaluated operand.
// Let pair-constructor be an exposition-only class defined as follows:
class pair_constructor {
    using pair_type = remove_cv_t<T>;
    constexpr auto do_construct (const pair_type & p) const {
        return make_obj_using_allocator<pair_type>(alloc_, p);
    }
    constexpr auto do_construct (pair_type && p) const {
// exposition only // exposition only
// exposition only
        return make_obj_using_allocator<pair_type>(alloc_, std::move(p));
    }
    const Alloc& alloc_; // exposition only U& u_; // exposition only
public:
    constexpr operator pair_type() const {
        return do_construct(std::forward<U>(u_));
    }
};
// Returns: make_tuple(pc), where pc is a pair-constructor object whose alloc_ member is initialized with alloc and whose u_ member is initialized with u.
int main() {
    cout  <<  n4910 << endl;
    return EXIT_SUCCESS;
}

編纂・実行結果(compile and go)

bash
$ clang++ p589.cpp -std=c++03 -o p589l -I. -Wall
In file included from p589.cpp:19:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/atomic:38:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
 ^
p589.cpp:26:37: warning: variadic templates are a C++11 extension [-Wc++11-extensions]
template<class T, class Alloc, class... Args>
                                    ^
p589.cpp:27:6: error: unknown type name 'constexpr'
     constexpr auto uses_allocator_construction_args(const Alloc& alloc,
     ^
p589.cpp:28:5: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
Args&&... args) noexcept;
    ^
p589.cpp:27:16: error: illegal storage class on function
     constexpr auto uses_allocator_construction_args(const Alloc& alloc,
               ^
p589.cpp:28:16: error: expected ';' at end of declaration
Args&&... args) noexcept;
               ^
               ;
p589.cpp:28:17: error: C++ requires a type specifier for all declarations
Args&&... args) noexcept;
                ^
p589.cpp:32:8: error: use of undeclared identifier 'allocator_arg_t'
 tuple<allocator_arg_t, const Alloc&, Args&&...>(
       ^
p589.cpp:33:23: error: expected ')'
         allocator_arg, alloc, std::forward<Args>(args)...)
                      ^
p589.cpp:32:49: note: to match this '('
 tuple<allocator_arg_t, const Alloc&, Args&&...>(
                                                ^
p589.cpp:33:60: error: expected ';' after top level declarator
         allocator_arg, alloc, std::forward<Args>(args)...)
                                                           ^
                                                           ;
p589.cpp:41:3: error: unknown type name 'constexpr'
  constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
  ^
p589.cpp:41:71: error: unknown type name 'piecewise_construct_t'
  constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
                                                                      ^
p589.cpp:42:52: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
                                             Tuple1&& x, Tuple2&& y) noexcept;
                                                   ^
p589.cpp:42:64: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
                                             Tuple1&& x, Tuple2&& y) noexcept;
                                                               ^
p589.cpp:41:13: error: illegal storage class on function
  constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
            ^
p589.cpp:42:69: error: expected ';' at end of declaration
                                             Tuple1&& x, Tuple2&& y) noexcept;
                                                                    ^
                                                                    ;
p589.cpp:42:70: error: C++ requires a type specifier for all declarations
                                             Tuple1&& x, Tuple2&& y) noexcept;
                                                                     ^
p589.cpp:45:3: error: expected unqualified-id
  return make_tuple(
  ^
p589.cpp:56:3: error: unknown type name 'constexpr'
  constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept;
  ^
p589.cpp:56:13: error: illegal storage class on function
  constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept;
            ^
p589.cpp:56:70: error: expected ';' at end of declaration
  constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept;
                                                                     ^
                                                                     ;
p589.cpp:56:71: error: C++ requires a type specifier for all declarations
  constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept;
                                                                      ^
p589.cpp:58:3: error: unknown type name 'constexpr'
  constexpr auto uses_allocator_construction_args(const Alloc& alloc,
  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
4 warnings and 20 errors generated.
rm: cannot remove 'p589l': No such file or directory
$ clang++ p589.cpp -std=c++2b -o p589l -I. -Wall
p589.cpp:32:31: error: unknown type name 'Alloc'
 tuple<allocator_arg_t, const Alloc&, Args&&...>(
                              ^
p589.cpp:33:23: error: expected ')'
         allocator_arg, alloc, std::forward<Args>(args)...)
                      ^
p589.cpp:32:49: note: to match this '('
 tuple<allocator_arg_t, const Alloc&, Args&&...>(
                                                ^
p589.cpp:33:60: error: expected ';' after top level declarator
         allocator_arg, alloc, std::forward<Args>(args)...)
                                                           ^
                                                           ;
p589.cpp:45:3: error: expected unqualified-id
  return make_tuple(
  ^
p589.cpp:60:1: error: expected parameter declarator
return uses_allocator_construction_args<T>(alloc, piecewise_construct,
^
p589.cpp:60:1: error: expected ')'
p589.cpp:58:50: note: to match this '('
  constexpr auto uses_allocator_construction_args(const Alloc& alloc,
                                                 ^
p589.cpp:69:8: error: expected parameter declarator
       return uses_allocator_construction_args<T>(alloc, piecewise_construct,
       ^
p589.cpp:69:8: error: expected ')'
p589.cpp:67:50: note: to match this '('
  constexpr auto uses_allocator_construction_args(const Alloc& alloc,
                                                 ^
p589.cpp:75:55: error: unknown type name 'Alloc'
constexpr auto uses_allocator_construction_args(const Alloc& alloc,
                                                      ^
p589.cpp:76:1: error: unknown type name 'U'
U&& u, V&& v) noexcept;
^
p589.cpp:76:8: error: unknown type name 'V'
U&& u, V&& v) noexcept;
       ^
p589.cpp:78:19: error: declaration of reference variable 'pr' requires an initializer
const pair<U, V>& pr) noexcept;
                  ^~
p589.cpp:78:21: error: expected ';' at end of declaration
const pair<U, V>& pr) noexcept;
                    ^
                    ;
p589.cpp:78:21: error: expected unqualified-id
p589.cpp:80:3: error: expected unqualified-id
  return uses_allocator_construction_args<T>(alloc, piecewise_construct,
  ^
p589.cpp:88:1: error: expected unqualified-id
return make_from_tuple<T>(uses_allocator_construction_args<T>(
^
p589.cpp:93:3: error: expected unqualified-id
  return apply([&]<class... U>(U&&... xs) {
  ^
p589.cpp:96:12: error: use of undeclared identifier 'U'
const pair<U, V>&& pr) noexcept;
           ^
p589.cpp:96:20: error: declaration of reference variable 'pr' requires an initializer
const pair<U, V>&& pr) noexcept;
                   ^~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

$ g++ p589.cpp -std=c++03 -o p589g -I. -Wall
In file included from /usr/local/include/c++/12.1.0/atomic:38,
                 from p589.cpp:19:
/usr/local/include/c++/12.1.0/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
   32 | #error This file requires compiler and library support \
      |  ^~~~~
p589.cpp:27:6: warning: identifier 'constexpr' is a keyword in C++11 [-Wc++11-compat]
   27 |      constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      |      ^~~~~~~~~
p589.cpp:28:17: warning: identifier 'noexcept' is a keyword in C++11 [-Wc++11-compat]
   28 | Args&&... args) noexcept;
      |                 ^~~~~~~~
p589.cpp:49:35: warning: identifier 'decltype' is a keyword in C++11 [-Wc++11-compat]
   49 |               alloc, std::forward<decltype(args1)>(args1)...);
      |                                   ^~~~~~~~
p589.cpp:26:37: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   26 | template<class T, class Alloc, class... Args>
      |                                     ^~~
p589.cpp:27:6: error: 'constexpr' does not name a type
   27 |      constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      |      ^~~~~~~~~
p589.cpp:27:6: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:32:2: error: 'tuple' does not name a type
   32 |  tuple<allocator_arg_t, const Alloc&, Args&&...>(
      |  ^~~~~
p589.cpp:39:55: error: expected unqualified-id before ',' token
   39 |                                              tuple<>{}, tuple<>{});
      |                                                       ^
p589.cpp:39:62: error: expected constructor, destructor, or type conversion before '<' token
   39 |                                              tuple<>{}, tuple<>{});
      |                                                              ^
p589.cpp:39:66: error: expected unqualified-id before ')' token
   39 |                                              tuple<>{}, tuple<>{});
      |                                                                  ^
p589.cpp:41:3: error: 'constexpr' does not name a type
   41 |   constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t,
      |   ^~~~~~~~~
p589.cpp:41:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:45:3: error: expected unqualified-id before 'return'
   45 |   return make_tuple(
      |   ^~~~~~
p589.cpp:50:12: error: expected unqualified-id before ',' token
   50 |           }, std::forward<Tuple1>(x)),
      |            ^
p589.cpp:50:26: error: expected constructor, destructor, or type conversion before '<' token
   50 |           }, std::forward<Tuple1>(x)),
      |                          ^
p589.cpp:54:12: error: expected unqualified-id before ',' token
   54 |           }, std::forward<Tuple2>(y)));
      |            ^
p589.cpp:54:26: error: expected constructor, destructor, or type conversion before '<' token
   54 |           }, std::forward<Tuple2>(y)));
      |                          ^
p589.cpp:56:3: error: 'constexpr' does not name a type
   56 |   constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept;
      |   ^~~~~~~~~
p589.cpp:56:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:58:3: error: 'constexpr' does not name a type
   58 |   constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      |   ^~~~~~~~~
p589.cpp:58:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:64:3: error: 'constexpr' does not name a type
   64 |   constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      |   ^~~~~~~~~
p589.cpp:64:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:67:3: error: 'constexpr' does not name a type
   67 |   constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      |   ^~~~~~~~~
p589.cpp:67:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:73:3: error: 'constexpr' does not name a type
   73 |   constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      |   ^~~~~~~~~
p589.cpp:73:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:75:1: error: 'constexpr' does not name a type
   75 | constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      | ^~~~~~~~~
p589.cpp:75:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:78:21: error: expected initializer before ')' token
   78 | const pair<U, V>& pr) noexcept;
      |                     ^
p589.cpp:80:3: error: expected unqualified-id before 'return'
   80 |   return uses_allocator_construction_args<T>(alloc, piecewise_construct,
      |   ^~~~~~
p589.cpp:84:3: error: 'constexpr' does not name a type
   84 |   constexpr auto uses_allocator_construction_args(const Alloc& alloc, U&& u) noexcept;
      |   ^~~~~~~~~
p589.cpp:84:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:85:37: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   85 | template<class T, class Alloc, class... Args>
      |                                     ^~~
p589.cpp:86:3: error: 'constexpr' does not name a type
   86 |   constexpr T make_obj_using_allocator(const Alloc& alloc, Args&&... args);
      |   ^~~~~~~~~
p589.cpp:86:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:88:1: error: expected unqualified-id before 'return'
   88 | return make_from_tuple<T>(uses_allocator_construction_args<T>(
      | ^~~~~~
p589.cpp:90:37: warning: variadic templates only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   90 | template<class T, class Alloc, class... Args>
      |                                     ^~~
p589.cpp:91:3: error: 'constexpr' does not name a type
   91 |   constexpr T* uninitialized_construct_using_allocator(T* p, const Alloc& alloc, Args&&... args);
      |   ^~~~~~~~~
p589.cpp:91:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:93:3: error: expected unqualified-id before 'return'
   93 |   return apply([&]<class... U>(U&&... xs) {
      |   ^~~~~~
p589.cpp:95:9: error: expected unqualified-id before ',' token
   95 |        }, uses_allocator_construction_args<T>(alloc, std::forward<Args>(args)...));
      |         ^
p589.cpp:95:43: error: expected constructor, destructor, or type conversion before '<' token
   95 |        }, uses_allocator_construction_args<T>(alloc, std::forward<Args>(args)...));
      |                                           ^
p589.cpp:96:12: error: 'U' was not declared in this scope
   96 | const pair<U, V>&& pr) noexcept;
      |            ^
p589.cpp:96:15: error: 'V' was not declared in this scope
   96 | const pair<U, V>&& pr) noexcept;
      |               ^
p589.cpp:96:16: error: template argument 1 is invalid
   96 | const pair<U, V>&& pr) noexcept;
      |                ^
p589.cpp:96:16: error: template argument 2 is invalid
p589.cpp:96:17: error: expected unqualified-id before '&&' token
   96 | const pair<U, V>&& pr) noexcept;
      |                 ^~
p589.cpp:98:21: error: 'A' was not declared in this scope
   98 | void FUN(const pair<A, B>&);
      |                     ^
p589.cpp:98:24: error: 'B' was not declared in this scope
   98 | void FUN(const pair<A, B>&);
      |                        ^
p589.cpp:98:25: error: template argument 1 is invalid
   98 | void FUN(const pair<A, B>&);
      |                         ^
p589.cpp:98:25: error: template argument 2 is invalid
p589.cpp:102:7: error: expected nested-name-specifier before 'pair_type'
  102 | using pair_type = remove_cv_t<T>;
      |       ^~~~~~~~~
p589.cpp:103:1: error: 'constexpr' does not name a type
  103 | constexpr auto do_construct (const pair_type & p) const { return make_obj_using_allocator<pair_type>(alloc_, p);
      | ^~~~~~~~~
p589.cpp:103:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:105:1: error: 'constexpr' does not name a type
  105 | constexpr auto do_construct (pair_type && p) const {
      | ^~~~~~~~~
p589.cpp:105:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p589.cpp:109:7: error: 'Alloc' does not name a type; did you mean 'alloca'?
  109 | const Alloc& alloc_; // exposition only U& u_; // exposition only
      |       ^~~~~
      |       alloca
p589.cpp:111:1: error: 'constexpr' does not name a type
  111 | constexpr operator pair_type() const {
      | ^~~~~~~~~
p589.cpp:111:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
rm: cannot remove 'p589g': No such file or directory

$ g++ p589.cpp -std=c++2b -o p589g -I. -Wall
p589.cpp:32:31: error: ISO C++ forbids declaration of 'type name' with no type [-fpermissive]
   32 |  tuple<allocator_arg_t, const Alloc&, Args&&...>(
      |                               ^~~~~
p589.cpp:32:48: error: template argument 2 is invalid
   32 |  tuple<allocator_arg_t, const Alloc&, Args&&...>(
      |                                                ^
p589.cpp:33:23: error: expected ')' before ',' token
   33 |          allocator_arg, alloc, std::forward<Args>(args)...)
      |                       ^
      |                       )
p589.cpp:32:49: note: to match this '('
   32 |  tuple<allocator_arg_t, const Alloc&, Args&&...>(
      |                                                 ^
p589.cpp:33:45: error: 'Args' was not declared in this scope
   33 |          allocator_arg, alloc, std::forward<Args>(args)...)
      |                                             ^~~~
p589.cpp:33:55: error: template-id 'forward<<expression error> >' used as a declarator
   33 |          allocator_arg, alloc, std::forward<Args>(args)...)
      |                                                       ^
p589.cpp:33:55: error: 'int std::forward' redeclared as different kind of entity
In file included from /usr/local/include/c++/12.1.0/bits/exception_ptr.h:43,
                 from /usr/local/include/c++/12.1.0/exception:168,
                 from /usr/local/include/c++/12.1.0/ios:39,
                 from /usr/local/include/c++/12.1.0/ostream:38,
                 from /usr/local/include/c++/12.1.0/iostream:39,
                 from p589.cpp:10:
/usr/local/include/c++/12.1.0/bits/move.h:89:5: note: previous declaration 'template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Tp>::type&&)'
   89 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^~~~~~~
p589.cpp:33:51: error: 'args' was not declared in this scope
   33 |          allocator_arg, alloc, std::forward<Args>(args)...)
      |                                                   ^~~~
p589.cpp:39:55: error: expected unqualified-id before ',' token
   39 |                                              tuple<>{}, tuple<>{});
      |                                                       ^
p589.cpp:39:64: error: invalid declarator before '{' token
   39 |                                              tuple<>{}, tuple<>{});
      |                                                                ^
p589.cpp:39:66: error: expected unqualified-id before ')' token
   39 |                                              tuple<>{}, tuple<>{});
      |                                                                  ^
p589.cpp:45:3: error: expected unqualified-id before 'return'
   45 |   return make_tuple(
      |   ^~~~~~
p589.cpp:50:12: error: expected unqualified-id before ',' token
   50 |           }, std::forward<Tuple1>(x)),
      |            ^
p589.cpp:50:27: error: 'Tuple1' was not declared in this scope
   50 |           }, std::forward<Tuple1>(x)),
      |                           ^~~~~~
p589.cpp:50:34: error: expected constructor, destructor, or type conversion before '(' token
   50 |           }, std::forward<Tuple1>(x)),
      |                                  ^
p589.cpp:54:12: error: expected unqualified-id before ',' token
   54 |           }, std::forward<Tuple2>(y)));
      |            ^
p589.cpp:54:27: error: 'Tuple2' was not declared in this scope
   54 |           }, std::forward<Tuple2>(y)));
      |                           ^~~~~~
p589.cpp:54:34: error: expected constructor, destructor, or type conversion before '(' token
   54 |           }, std::forward<Tuple2>(y)));
      |                                  ^
p589.cpp:60:1: error: expected identifier before 'return'
   60 | return uses_allocator_construction_args<T>(alloc, piecewise_construct,
      | ^~~~~~
p589.cpp:60:1: error: expected ',' or '...' before 'return'
p589.cpp:62:81: error: expected ')' before ';' token
   62 |                                            forward_as_tuple(std::forward<V>(v)));
      |                                                                                 ^
      |                                                                                 )
p589.cpp:58:50: note: to match this '('
   58 |   constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      |                                                  ^
p589.cpp:69:8: error: expected identifier before 'return'
   69 |        return uses_allocator_construction_args<T>(alloc, piecewise_construct,
      |        ^~~~~~
p589.cpp:69:8: error: expected ',' or '...' before 'return'
p589.cpp:71:79: error: expected ')' before ';' token
   71 |                                                   forward_as_tuple(pr.second));
      |                                                                               ^
      |                                                                               )
p589.cpp:67:50: note: to match this '('
   67 |   constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      |                                                  ^
p589.cpp:75:55: error: 'Alloc' does not name a type; did you mean 'alloca'?
   75 | constexpr auto uses_allocator_construction_args(const Alloc& alloc,
      |                                                       ^~~~~
      |                                                       alloca
p589.cpp:76:1: error: 'U' has not been declared
   76 | U&& u, V&& v) noexcept;
      | ^
p589.cpp:76:8: error: 'V' has not been declared
   76 | U&& u, V&& v) noexcept;
      |        ^
p589.cpp:78:21: error: expected initializer before ')' token
   78 | const pair<U, V>& pr) noexcept;
      |                     ^
p589.cpp:80:3: error: expected unqualified-id before 'return'
   80 |   return uses_allocator_construction_args<T>(alloc, piecewise_construct,
      |   ^~~~~~
p589.cpp:88:1: error: expected unqualified-id before 'return'
   88 | return make_from_tuple<T>(uses_allocator_construction_args<T>(
      | ^~~~~~
p589.cpp:93:3: error: expected unqualified-id before 'return'
   93 |   return apply([&]<class... U>(U&&... xs) {
      |   ^~~~~~
p589.cpp:95:9: error: expected unqualified-id before ',' token
   95 |        }, uses_allocator_construction_args<T>(alloc, std::forward<Args>(args)...));
      |         ^
p589.cpp:95:44: error: 'T' was not declared in this scope
   95 |        }, uses_allocator_construction_args<T>(alloc, std::forward<Args>(args)...));
      |                                            ^
p589.cpp:95:11: error: specializing member '::uses_allocator_construction_args<<expression error> >' requires 'template<>' syntax
   95 |        }, uses_allocator_construction_args<T>(alloc, std::forward<Args>(args)...));
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p589.cpp:96:12: error: 'U' was not declared in this scope
   96 | const pair<U, V>&& pr) noexcept;
      |            ^
p589.cpp:96:15: error: 'V' was not declared in this scope
   96 | const pair<U, V>&& pr) noexcept;
      |               ^
p589.cpp:96:16: error: template argument 1 is invalid
   96 | const pair<U, V>&& pr) noexcept;
      |                ^
p589.cpp:96:16: error: template argument 2 is invalid
p589.cpp:96:22: error: expected initializer before ')' token
   96 | const pair<U, V>&& pr) noexcept;
      |                      ^
p589.cpp:98:21: error: 'A' was not declared in this scope
   98 | void FUN(const pair<A, B>&);
      |                     ^
p589.cpp:98:24: error: 'B' was not declared in this scope
   98 | void FUN(const pair<A, B>&);
      |                        ^
p589.cpp:98:25: error: template argument 1 is invalid
   98 | void FUN(const pair<A, B>&);
      |                         ^
p589.cpp:98:25: error: template argument 2 is invalid
p589.cpp:102:31: error: 'T' was not declared in this scope
  102 | using pair_type = remove_cv_t<T>;
      |                               ^
p589.cpp:102:32: error: template argument 1 is invalid
  102 | using pair_type = remove_cv_t<T>;
      |                                ^
p589.cpp:103:36: error: 'pair_type' does not name a type
  103 | constexpr auto do_construct (const pair_type & p) const { return make_obj_using_allocator<pair_type>(alloc_, p);
      |                                    ^~~~~~~~~
p589.cpp:105:30: error: 'pair_type' has not been declared
  105 | constexpr auto do_construct (pair_type && p) const {
      |                              ^~~~~~~~~
p589.cpp:109:7: error: 'Alloc' does not name a type; did you mean 'alloca'?
  109 | const Alloc& alloc_; // exposition only U& u_; // exposition only
      |       ^~~~~
      |       alloca
p589.cpp:111:20: error: expected type-specifier before 'pair_type'
  111 | constexpr operator pair_type() const {
      |                    ^~~~~~~~~
p589.cpp: In member function 'constexpr auto pair_constructor::do_construct(const int&) const':
p589.cpp:103:91: error: 'pair_type' was not declared in this scope
  103 | constexpr auto do_construct (const pair_type & p) const { return make_obj_using_allocator<pair_type>(alloc_, p);
      |                                                                                           ^~~~~~~~~
p589.cpp:103:102: error: 'alloc_' was not declared in this scope; did you mean 'alloca'?
  103 | constexpr auto do_construct (const pair_type & p) const { return make_obj_using_allocator<pair_type>(alloc_, p);
      |                                                                                                      ^~~~~~
      |                                                                                                      alloca
p589.cpp:103:16: error: invalid return type 'auto' of 'constexpr' function 'constexpr auto pair_constructor::do_construct(const int&) const'
  103 | constexpr auto do_construct (const pair_type & p) const { return make_obj_using_allocator<pair_type>(alloc_, p);
      |                ^~~~~~~~~~~~
p589.cpp: In member function 'constexpr auto pair_constructor::do_construct(int&&) const':
p589.cpp:108:33: error: 'pair_type' was not declared in this scope
  108 | return make_obj_using_allocator<pair_type>(alloc_, std::move(p)); }
      |                                 ^~~~~~~~~
p589.cpp:108:44: error: 'alloc_' was not declared in this scope; did you mean 'alloca'?
  108 | return make_obj_using_allocator<pair_type>(alloc_, std::move(p)); }
      |                                            ^~~~~~
      |                                            alloca
p589.cpp:105:16: error: invalid return type 'auto' of 'constexpr' function 'constexpr auto pair_constructor::do_construct(int&&) const'
  105 | constexpr auto do_construct (pair_type && p) const {
      |                ^~~~~~~~~~~~

検討事項(agenda)

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

Script

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

参考資料(reference)

cpprefjp - C++日本語リファレンス

コンパイラの実装状況

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

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

自己参照(self reference)

コピペコンパイルエラーあるある

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

dockerにclang

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

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

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

C++ sample list

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

astyle 使ってみた

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
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9

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

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

文書履歴(document history)

ver. 0.01 初稿  20220717

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?