エンジニア夏休み企画
個人開発と読書感想文に焦点を当てたのは良い企画だと思った。
<この項は書きかけです。順次追記します。>
読書感想文
CコンパイラによるC言語規格の読書感想文として掲載しています。
コンパイル実験が、C++N4910に対する、G++とClang++による感想文だということご理解いただけると幸いです。
読書感想文は人間かAIだけが作るものとは限りません。
本(電子書籍を含む)を入力として、その内容に対する文字列を読書感想文として受け止めましょう。
元の文章をあり方、コンパイルできるように電子化しておくこと、コンパイラが解釈可能な断片の作り方など。
個人開発
【個人開発】 効率的な背景 <エンジニア夏休み企画>
Cコンパイラの試験を一人でもくもくとやっているのは個人開発の一つの姿です。
箱庭
箱庭もくもく会 #10 日時:2022/09/14(水) 17:30-19:30
はじめに(Introduction)
N4910 Working Draft, Standard for Programming Language C++
C++ n4910は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 のWG21を含むいくつかのWGでは、可能な限り作業文書を公開し、幅広い意見を求めています。
ISO/IEC JTC1 SC7からISO/IEC JTC1 SC22リエゾンとして、2000年頃、C/C++の品質向上に貢献しようとした活動をしていたことがあります。その頃は、まだISO/IEC TS 17961の原案が出る前です。Cの精神が優勢で、セキュリティ対策は補助的な位置付けでした。ISO/IEC TS 17961の制定と、C/C++のライブラリ類の見直しと、C++の進化はどんどん進んでいきます。
進化の具合が、どちらに行こうとしているかは、コンパイルて実行させてみないとわかりません。C/C++の規格案の電子ファイルは、そのままコンパイルできる形式であるとよいと主張してきました。MISRA-C/C++, CERTC/C++でも同様です。MISRA-C/C++は、Example Suiteという形で、コード断片をコンパイルできる形で提供するようになりました。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, 箱庭プロジェクト、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。
背景(back ground)
C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。
この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の3つの情報に基づいています。
cpprefjp - C++日本語リファレンス
コンパイラの実装状況
また
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
20220826 以前
Debian clang version 14.0.5-++20220610033153+c12386ae247c-1~exp1~20220610153237.151
Target: x86_64-pc-linux-gnu, Thread model: posix, InstalledDir: /usr/bin
20220827 以降
Debian clang version 14.0.6-++20220622053050+f28c006a5895-1~exp1~20220622173135.152
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.
31.11 Synchronized output streams [syncstream] C++N4910:2022 (694) p1572.cpp
算譜(source code)
// 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 = "31.11 Synchronized output streams [syncstream] C++N4910:2022 (694) p1572.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 "N4910.h"
using namespace std;
// 31.11.1 Header <syncstream> synopsis [syncstream.syn]
#include <ostream> // see 31.7.2
namespace std {
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
class basic_syncbuf;
// 31.11.2.6, specialized algorithms
template<class charT, class traits, class Allocator>
void swap(basic_syncbuf<charT, traits, Allocator>&,
basic_syncbuf<charT, traits, Allocator>&);
using syncbuf = basic_syncbuf<char>;
using wsyncbuf = basic_syncbuf<wchar_t>;
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
class basic_osyncstream;
using osyncstream = basic_osyncstream<char>;
using wosyncstream = basic_osyncstream<wchar_t>;
}
// The header <syncstream> provides a mechanism to synchronize execution agents writing to the same stream.
// 31.11.2 Class template basic_syncbuf [syncstream.syncbuf]
// 31.11.2.1 Overview [syncstream.syncbuf.overview]
namespace std {
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
class basic_syncbuf : public basic_streambuf<charT, traits> {
public:
using char_type = charT;
using int_type = typename traits::int_type;
using pos_type = typename traits::pos_type;
using off_type = typename traits::off_type;
using traits_type = traits;
using allocator_type = Allocator;
using streambuf_type = basic_streambuf<charT, traits>;
// 31.11.2.2, construction and destruction basic_syncbuf()
:
basic_syncbuf(nullptr) {}
explicit basic_syncbuf(streambuf_type* obuf)
: basic_syncbuf(obuf, Allocator()) {} basic_syncbuf(streambuf_type*, const Allocator&);
basic_syncbuf(basic_syncbuf&&);
~basic_syncbuf();
// 31.11.2.3, assignment and swap basic_syncbuf& operator=(basic_syncbuf&&); void swap(basic_syncbuf&);
// 31.11.2.4, member functions
bool emit();
streambuf_type* get_wrapped() const noexcept;
allocator_type get_allocator() const noexcept;
void set_emit_on_sync(bool) noexcept;
protected:
// 31.11.2.5, overridden virtual functions int sync() override;
private:
streambuf_type* wrapped;
bool emit_on_sync{};
};
}
// exposition only // exposition only
// Class template basic_syncbuf stores character data written to it, known as the associated output, into internal buffers allocated using the object’s allocator. The associated output is transferred to the wrapped stream buffer object *wrapped when emit() is called or when the basic_syncbuf object is destroyed. Such transfers are atomic with respect to transfers by other basic_syncbuf objects with the same wrapped stream buffer object.
// 31.11.2.2 Construction and destruction [syncstream.syncbuf.cons]
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
// Effects: Sets wrapped to obuf.
// Postconditions: get_wrapped() == obuf and get_allocator() == allocator are true.
// Throws: Nothing unless an exception is thrown by the construction of a mutex or by memory allocation.
// Remarks: A copy of allocator is used to allocate memory for internal buffers holding the associated output.
basic_syncbuf(basic_syncbuf&& other);
// Postconditions: The value returned by this->get_wrapped() is the value returned by other.get_- wrapped() prior to calling this constructor. Output stored in other prior to calling this constructor will be stored in *this afterwards. other.pbase() == other.pptr() and other.get_wrapped() == nullptr are true.
// Remarks: This constructor disassociates other from its wrapped stream buffer, ensuring destruction of other produces no output.
~basic_syncbuf();
// Effects: Calls emit().
// Throws: Nothing. If an exception is thrown from emit(), the destructor catches and ignores that exception.
// 31.11.2.3 Assignment and swap [syncstream.syncbuf.assign]
basic_syncbuf& operator=(basic_syncbuf&& rhs);
// Effects: Calls emit() then move assigns from rhs. After the move assignment *this has the observable state it would have had if it had been move constructed from rhs (31.11.2.2).
// Postconditions: — rhs.get_wrapped() == nullptr is true.
// — this->get_allocator() == rhs.get_allocator() is true when allocator_traits<Allocator>::propagate_on_container_move_assignment::value is true; otherwise, the allocator is unchanged. Returns: *this.
// Remarks: This assignment operator disassociates rhs from its wrapped stream buffer, ensuring destruction of rhs produces no output.
void swap(basic_syncbuf& other);
// Preconditions: Either allocator_traits<Allocator>::propagate_on_container_swap::value is true or this->get_allocator() == other.get_allocator() is true.
// Effects: Exchanges the state of *this and other.
// 31.11.2.4 Member functions [syncstream.syncbuf.members]
bool emit();
// Effects: Atomically transfers the associated output of *this to the stream buffer *wrapped, so that it appears in the output stream as a contiguous sequence of characters. wrapped->pubsync() is called if and only if a call was made to sync() since the most recent call to emit(), if any.
// Synchronization: All emit() calls transferring characters to the same stream buffer object appear to execute in a total order consistent with the “happens before” relation (6.9.2.2), where each emit() call synchronizes with subsequent emit() calls in that total order.
// Postconditions: On success, the associated output is empty.
// Returns: true if all of the following conditions hold; otherwise false:
// — wrapped == nullptr is false.
// — All of the characters in the associated output were successfully transferred. —
// The call to wrapped->pubsync() (if any) succeeded.
// Remarks: May call member functions of wrapped while holding a lock uniquely associated with wrapped. streambuf_type* get_wrapped() const noexcept;
// Returns: wrapped.
allocator_type get_allocator() const noexcept;
// Returns: A copy of the allocator that was set in the constructor or assignment operator.
void set_emit_on_sync(bool b) noexcept;
// Effects: emit_on_sync = b.
// 31.11.2.5 Overridden virtual functions [syncstream.syncbuf.virtuals]
int sync() override;
// Effects: Records that the wrapped stream buffer is to be flushed. Then, if emit_on_sync is true, calls emit().
// [Note 1: If emit_on_sync is false, the actual flush is delayed until a call to emit(). —end note] Returns: If emit() was called and returned false, returns -1; otherwise 0.
// 31.11.2.6 Specialized algorithms [syncstream.syncbuf.special]
template<class charT, class traits, class Allocator>
void swap(basic_syncbuf<charT, traits, Allocator>& a,
basic_syncbuf<charT, traits, Allocator>& b);
// Effects: Equivalent to a.swap(b).
// 31.11.3 Class template basic_osyncstream [syncstream.osyncstream]
// 31.11.3.1 Overview [syncstream.osyncstream.overview]
namespace std {
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
class basic_osyncstream : public basic_ostream<charT, traits> {
public:
using char_type = charT;
using int_type = typename traits::int_type;
using pos_type = typename traits::pos_type;
using off_type = typename traits::off_type;
using traits_type = traits;
using allocator_type = Allocator;
using streambuf_type = basic_streambuf<charT, traits>;
using syncbuf_type = basic_syncbuf<charT, traits, Allocator>;
// 31.11.3.2, construction and destruction
basic_osyncstream(streambuf_type*, const Allocator&);
explicit basic_osyncstream(streambuf_type* obuf)
: basic_osyncstream(obuf, Allocator()) {}
basic_osyncstream(basic_ostream<charT, traits>& os, const Allocator& allocator)
: basic_osyncstream(os.rdbuf(), allocator) {}
explicit basic_osyncstream(basic_ostream<charT, traits>& os)
: basic_osyncstream(os, Allocator()) {} basic_osyncstream(basic_osyncstream&&) noexcept;
~basic_osyncstream();
// assignment
basic_osyncstream& operator=(basic_osyncstream&&) noexcept;
// 31.11.3.3, member functions
void emit();
streambuf_type* get_wrapped() const noexcept;
syncbuf_type* rdbuf() const noexcept {
return const_cast<syncbuf_type*>(addressof(sb));
}
private:
syncbuf_type sb; // exposition only
};
}
// Allocator shall meet the Cpp17Allocator requirements (16.4.4.6.1).
// [Example 1: A named variable can be used within a block statement for streaming.
// Effects: Initializes sb from buf and allocator. Initializes the base class with basic_ostream<charT, traits>(addressof(sb)).
// [Note 1: The member functions of the provided stream buffer can be called from emit() while a lock is held, which might result in a deadlock if used incautiously.
// Returns: sb.get_wrapped().
void sample3() {
osyncstream bout(cout);
bout << "Hello, ";
bout << "World!";
bout << endl; // flush is noted bout << "and more!\n";
// characters are transferred and cout is flushed
// [Example 2: A temporary object can be used for streaming within a single statement.
osyncstream(cout) << "Hello, " << "World!" << '\n';
// In this example, cout is not flushed.
// 31.11.3.2 Construction and destruction [syncstream.osyncstream.cons]
basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
}
// Postconditions: get_wrapped() == buf is true. basic_osyncstream(basic_osyncstream&& other) noexcept;
// Effects: Move constructs the base class and sb from the corresponding subobjects of other, and calls basic_ostream<charT, traits>::set_rdbuf(addressof(sb)).
// Postconditions: The value returned by get_wrapped() is the value returned by os.get_wrapped() prior to calling this constructor. nullptr == other.get_wrapped() is true.
// 31.11.3.3 Member functions [syncstream.osyncstream.members]
void emit();
// Effects: Behaves as an unformatted output function (31.7.5.4). After constructing a sentry object, calls sb.emit(). If that call returns false, calls setstate(ios_base::badbit).
// [Example 1: A flush on a basic_osyncstream does not flush immediately: { }
bout << "Greetings." << '\n';
// characters transferred; cout not flushed
osyncstream bout(cout);
bout << "Hello," << '\n';
bout.emit();
bout << "World!" << endl;
bout.emit();
// no flush
// characters transferred; cout not flushed // flush noted; cout not flushed
// characters transferred; cout flushed
// no flush
// [Example 2: The function emit() can be used to handle exceptions from operations on the underlying stream.
void sample()
{
osyncstream bout(cout);
bout << "Hello, " << "World!" << '\n';
try {
bout.emit();
} catch (...) {
// handle exception
}
}
streambuf_type* get_wrapped() const noexcept;
// [Example 3: Obtaining the wrapped stream buffer with get_wrapped() allows wrapping it again with an osyncstream. For example,
void sample2()
{
osyncstream bout1(cout);
bout1 << "Hello, ";
{
osyncstream(bout1.get_wrapped()) << "Goodbye, " << "Planet!" << '\n';
}
bout1 << "World!" << '\n';
}
//produces the uninterleaved output Goodbye, Planet! Hello, World!
int main() {
cout << n4910 << endl;
return EXIT_SUCCESS;
}
編纂・実行結果(compile and go)
$ clang++ p1572.cpp -std=03 -o p1572l -I. -Wall
In file included from p1572.cpp:10:
In file included from ./N4910.h:11:
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 \
^
p1572.cpp:17:95: error: a space is required between consecutive right angle brackets (use '> >')
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^~
> >
p1572.cpp:23:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using syncbuf = basic_syncbuf<char>;
^
p1572.cpp:24:22: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using wsyncbuf = basic_syncbuf<wchar_t>;
^
p1572.cpp:25:95: error: a space is required between consecutive right angle brackets (use '> >')
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^~
> >
p1572.cpp:27:25: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using osyncstream = basic_osyncstream<char>;
^
p1572.cpp:28:26: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using wosyncstream = basic_osyncstream<wchar_t>;
^
p1572.cpp:34:93: error: a space is required between consecutive right angle brackets (use '> >')
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^~
> >
p1572.cpp:34:40: error: template parameter redefines default argument
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
p1572.cpp:17:42: note: previous default template argument defined here
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
p1572.cpp:34:78: error: template parameter redefines default argument
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
p1572.cpp:17:80: note: previous default template argument defined here
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
p1572.cpp:37:19: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using char_type = charT;
^
p1572.cpp:38:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using int_type = typename traits::int_type;
^
p1572.cpp:39:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using pos_type = typename traits::pos_type;
^
p1572.cpp:40:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using off_type = typename traits::off_type;
^
p1572.cpp:41:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using traits_type = traits;
^
p1572.cpp:42:24: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using allocator_type = Allocator;
^
p1572.cpp:43:26: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using streambuf_type = basic_streambuf<charT, traits>;
^
p1572.cpp:45:21: error: use of undeclared identifier 'nullptr'
: basic_syncbuf(nullptr) {}
^
p1572.cpp:45:5: error: C++ requires a type specifier for all declarations
: basic_syncbuf(nullptr) {}
^
p1572.cpp:47:116: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
: basic_syncbuf(obuf, Allocator()) {} basic_syncbuf(streambuf_type*, const Allocator&); basic_syncbuf(basic_syncbuf&&);
^
p1572.cpp:52:36: error: expected ';' at end of declaration list
streambuf_type* get_wrapped() const noexcept; allocator_type get_allocator() const noexcept; void set_emit_on_sync(bool) noexcept;
^
;
p1572.cpp:52:83: error: expected ';' at end of declaration list
streambuf_type* get_wrapped() const noexcept; allocator_type get_allocator() const noexcept; void set_emit_on_sync(bool) noexcept;
^
;
p1572.cpp:52:121: error: expected ';' at end of declaration list
streambuf_type* get_wrapped() const noexcept; allocator_type get_allocator() const noexcept; void set_emit_on_sync(bool) noexcept;
^
;
p1572.cpp:57:10: error: function definition does not declare parameters
bool emit_on_sync{};
^
p1572.cpp:62:18: error: unknown type name 'streambuf_type'
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
^
p1572.cpp:62:46: error: unknown type name 'Allocator'
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
^
p1572.cpp:62:4: error: C++ requires a type specifier for all declarations
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
^
p1572.cpp:67:6: error: C++ requires a type specifier for all declarations
basic_syncbuf(basic_syncbuf&& other);
^
p1572.cpp:67:36: error: use of undeclared identifier 'other'
basic_syncbuf(basic_syncbuf&& other);
^
p1572.cpp:70:2: error: identifier 'basic_syncbuf' after '~' in destructor name does not name a type
~basic_syncbuf();
^
p1572.cpp:35:9: note: non-type declaration found by destructor name lookup
class basic_syncbuf : public basic_streambuf<charT, traits> {
^
p1572.cpp:74:1: error: use of class template 'basic_syncbuf' requires template arguments
basic_syncbuf& operator=(basic_syncbuf&& rhs);
^
p1572.cpp:35:9: note: template is declared here
class basic_syncbuf : public basic_streambuf<charT, traits> {
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
12 warnings and 20 errors generated.
$ clang++ p1572.cpp -std=2b -o p1572l -I. -Wall
p1572.cpp:34:40: error: template parameter redefines default argument
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
p1572.cpp:17:42: note: previous default template argument defined here
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
p1572.cpp:34:78: error: template parameter redefines default argument
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
p1572.cpp:17:80: note: previous default template argument defined here
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
p1572.cpp:45:30: error: anonymous bit-field cannot have a default member initializer
: basic_syncbuf(nullptr) {}
^
p1572.cpp:45:5: error: C++ requires a type specifier for all declarations
: basic_syncbuf(nullptr) {}
^
p1572.cpp:62:18: error: unknown type name 'streambuf_type'
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
^
p1572.cpp:62:46: error: unknown type name 'Allocator'
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
^
p1572.cpp:62:4: error: deduction guide must be declared in the same scope as template 'std::basic_syncbuf'
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
^
p1572.cpp:35:9: note: template is declared here
class basic_syncbuf : public basic_streambuf<charT, traits> {
^
p1572.cpp:62:4: error: deduction guide declaration without trailing return type
basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
^
p1572.cpp:67:20: error: use of class template 'basic_syncbuf' requires template arguments; argument deduction not allowed in function prototype
basic_syncbuf(basic_syncbuf&& other);
^~~~~~~~~~~~~
p1572.cpp:35:9: note: template is declared here
class basic_syncbuf : public basic_streambuf<charT, traits> {
^
p1572.cpp:67:6: error: deduction guide must be declared in the same scope as template 'std::basic_syncbuf'
basic_syncbuf(basic_syncbuf&& other);
^
p1572.cpp:35:9: note: template is declared here
class basic_syncbuf : public basic_streambuf<charT, traits> {
^
p1572.cpp:67:6: error: deduction guide declaration without trailing return type
basic_syncbuf(basic_syncbuf&& other);
^
p1572.cpp:70:2: error: identifier 'basic_syncbuf' after '~' in destructor name does not name a type
~basic_syncbuf();
^
p1572.cpp:35:9: note: non-type declaration found by destructor name lookup
class basic_syncbuf : public basic_streambuf<charT, traits> {
^
p1572.cpp:74:26: error: use of class template 'basic_syncbuf' requires template arguments; argument deduction not allowed in function prototype
basic_syncbuf& operator=(basic_syncbuf&& rhs);
^~~~~~~~~~~~~
p1572.cpp:35:9: note: template is declared here
class basic_syncbuf : public basic_streambuf<charT, traits> {
^
p1572.cpp:74:1: error: use of class template 'basic_syncbuf' requires template arguments; argument deduction not allowed in function return type
basic_syncbuf& operator=(basic_syncbuf&& rhs);
^~~~~~~~~~~~~
p1572.cpp:35:9: note: template is declared here
class basic_syncbuf : public basic_streambuf<charT, traits> {
^
p1572.cpp:79:11: error: use of class template 'basic_syncbuf' requires template arguments; argument deduction not allowed in function prototype
void swap(basic_syncbuf& other);
^~~~~~~~~~~~~
p1572.cpp:35:9: note: template is declared here
class basic_syncbuf : public basic_streambuf<charT, traits> {
^
p1572.cpp:93:1: error: unknown type name 'allocator_type'
allocator_type get_allocator() const noexcept;
^
p1572.cpp:93:32: error: non-member function cannot have 'const' qualifier
allocator_type get_allocator() const noexcept;
^~~~~~
p1572.cpp:98:12: error: 'override' specifier is not allowed outside a class definition
int sync() override;
^~~~~~~~
p1572.cpp:109:40: error: template parameter redefines default argument
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
p1572.cpp:25:42: note: previous default template argument defined here
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
$ g++ p1572.cpp -std=03 -o p1572g -I. -Wall
In file included from /usr/local/include/c++/12.1.0/atomic:38,
from N4910.h:11,
from p1572.cpp:10:
/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 \
| ^~~~~
p1572.cpp:45:21: warning: identifier 'nullptr' is a keyword in C++11 [-Wc++11-compat]
45 | : basic_syncbuf(nullptr) {}
| ^~~~~~~
p1572.cpp:52:37: warning: identifier 'noexcept' is a keyword in C++11 [-Wc++11-compat]
52 | streambuf_type* get_wrapped() const noexcept; allocator_type get_allocator() const noexcept; void set_emit_on_sync(bool) noexcept;
| ^~~~~~~~
p1572.cpp:17:95: error: spurious '>>', use '>' to terminate a template argument list
17 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~
p1572.cpp:17:80: error: two or more data types in declaration of 'type name'
17 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~~~~~~~~~~~~~~~~
p1572.cpp:18:26: error: expected '>' before ';' token
18 | class basic_syncbuf;
| ^
p1572.cpp:18:26: error: expected unqualified-id before ';' token
p1572.cpp:21:17: error: 'std::basic_syncbuf' is not a template
21 | void swap(basic_syncbuf<charT, traits, Allocator>&,
| ^~~~~~~~~~~~~
p1572.cpp:22:17: error: 'std::basic_syncbuf' is not a template
22 | basic_syncbuf<charT, traits, Allocator>&);
| ^~~~~~~~~~~~~
p1572.cpp:23:11: error: expected nested-name-specifier before 'syncbuf'
23 | using syncbuf = basic_syncbuf<char>;
| ^~~~~~~
p1572.cpp:24:11: error: expected nested-name-specifier before 'wsyncbuf'
24 | using wsyncbuf = basic_syncbuf<wchar_t>;
| ^~~~~~~~
p1572.cpp:25:95: error: spurious '>>', use '>' to terminate a template argument list
25 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~
p1572.cpp:25:80: error: two or more data types in declaration of 'type name'
25 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~~~~~~~~~~~~~~~~
p1572.cpp:26:30: error: expected '>' before ';' token
26 | class basic_osyncstream;
| ^
p1572.cpp:26:30: error: expected unqualified-id before ';' token
p1572.cpp:27:11: error: expected nested-name-specifier before 'osyncstream'
27 | using osyncstream = basic_osyncstream<char>;
| ^~~~~~~~~~~
p1572.cpp:28:11: error: expected nested-name-specifier before 'wosyncstream'
28 | using wosyncstream = basic_osyncstream<wchar_t>;
| ^~~~~~~~~~~~
p1572.cpp:34:93: error: spurious '>>', use '>' to terminate a template argument list
34 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~
p1572.cpp:35:63: error: definition of 'class std::basic_syncbuf' inside template parameter list
35 | class basic_syncbuf : public basic_streambuf<charT, traits> {
| ^
p1572.cpp:34:78: error: two or more data types in declaration of 'type name'
34 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~~~~~~~~~~~~~~~~
p1572.cpp:58:2: error: expected '>' before ';' token
58 | }; }
| ^
p1572.cpp:58:2: error: expected unqualified-id before ';' token
p1572.cpp:62:32: error: expected ')' before '*' token
62 | basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
| ~ ^
| )
p1572.cpp:67:33: error: expected ')' before '&&' token
67 | basic_syncbuf(basic_syncbuf&& other);
| ~ ^~
| )
p1572.cpp:70:17: error: expected constructor, destructor, or type conversion before ';' token
70 | ~basic_syncbuf();
| ^
p1572.cpp:74:39: error: expected ',' or '...' before '&&' token
74 | basic_syncbuf& operator=(basic_syncbuf&& rhs);
| ^~
p1572.cpp:74:16: error: 'std::basic_syncbuf& operator=(std::basic_syncbuf)' must be a non-static member function
74 | basic_syncbuf& operator=(basic_syncbuf&& rhs);
| ^~~~~~~~
p1572.cpp:93:1: error: 'allocator_type' does not name a type
93 | allocator_type get_allocator() const noexcept;
| ^~~~~~~~~~~~~~
p1572.cpp:95:31: error: expected initializer before 'noexcept'
95 | void set_emit_on_sync(bool b) noexcept;
| ^~~~~~~~
p1572.cpp:98:10: warning: override controls (override/final) only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
98 | int sync() override;
| ^
p1572.cpp:98:12: error: virt-specifiers in 'sync' not allowed outside a class definition
98 | int sync() override;
| ^~~~~~~~
p1572.cpp:103:13: error: 'std::basic_syncbuf' is not a template
103 | void swap(basic_syncbuf<charT, traits, Allocator>& a,
| ^~~~~~~~~~~~~
p1572.cpp:104:13: error: 'std::basic_syncbuf' is not a template
104 | basic_syncbuf<charT, traits, Allocator>& b);
| ^~~~~~~~~~~~~
p1572.cpp:109:93: error: spurious '>>', use '>' to terminate a template argument list
109 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~
p1572.cpp:110:65: error: definition of 'class std::basic_osyncstream' inside template parameter list
110 | class basic_osyncstream : public basic_ostream<charT, traits> {
| ^
p1572.cpp:109:78: error: two or more data types in declaration of 'type name'
109 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~~~~~~~~~~~~~~~~
p1572.cpp:136:2: error: expected '>' before ';' token
136 | }; }
| ^
p1572.cpp:136:2: error: expected unqualified-id before ';' token
p1572.cpp: In function 'void sample3()':
p1572.cpp:143:1: error: 'osyncstream' was not declared in this scope
143 | osyncstream bout(cout);
| ^~~~~~~~~~~
p1572.cpp:144:1: error: 'bout' was not declared in this scope
144 | bout << "Hello, ";
| ^~~~
p1572.cpp:152:22: error: 'streambuf_type' was not declared in this scope
152 | basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
| ^~~~~~~~~~~~~~
p1572.cpp:152:38: error: 'buf' was not declared in this scope
152 | basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
| ^~~
p1572.cpp:152:69: error: invalid use of incomplete type 'class std::basic_osyncstream'
152 | basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
| ^
p1572.cpp:110:9: note: forward declaration of 'class std::basic_osyncstream'
110 | class basic_osyncstream : public basic_ostream<charT, traits> {
| ^~~~~~~~~~~~~~~~~
p1572.cpp:152:21: error: expected primary-expression before '(' token
152 | basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
| ^
p1572.cpp:152:43: error: expected primary-expression before 'const'
152 | basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
| ^~~~~
p1572.cpp: At global scope:
p1572.cpp:158:6: error: ambiguating new declaration of 'void emit()'
158 | void emit();
| ^~~~
p1572.cpp:83:6: note: old declaration 'bool emit()'
83 | bool emit();
| ^~~~
p1572.cpp:161:1: error: 'bout' does not name a type
161 | bout << "Greetings." << '\n';
| ^~~~
p1572.cpp:163:1: error: 'osyncstream' does not name a type
163 | osyncstream bout(cout);
| ^~~~~~~~~~~
p1572.cpp:164:1: error: 'bout' does not name a type
164 | bout << "Hello," << '\n';
| ^~~~
p1572.cpp:165:1: error: 'bout' does not name a type
165 | bout.emit();
| ^~~~
p1572.cpp:166:1: error: 'bout' does not name a type
166 | bout << "World!" << endl;
| ^~~~
p1572.cpp:167:1: error: 'bout' does not name a type
167 | bout.emit();
| ^~~~
p1572.cpp: In function 'void sample()':
p1572.cpp:175:5: error: 'osyncstream' was not declared in this scope
175 | osyncstream bout(cout);
| ^~~~~~~~~~~
p1572.cpp:176:5: error: 'bout' was not declared in this scope
176 | bout << "Hello, " << "World!" << '\n';
| ^~~~
p1572.cpp: At global scope:
p1572.cpp:182:1: error: 'streambuf_type' does not name a type
182 | streambuf_type* get_wrapped() const noexcept;
| ^~~~~~~~~~~~~~
p1572.cpp: In function 'void sample2()':
p1572.cpp:186:10: error: 'osyncstream' was not declared in this scope
186 | osyncstream bout1(cout);
| ^~~~~~~~~~~
p1572.cpp:187:10: error: 'bout1' was not declared in this scope
187 | bout1 << "Hello, ";
| ^~~~~
$ g++ p1572.cpp -std=2b -o p1572g -I. -Wall
p1572.cpp:34:25: error: redefinition of default argument for 'class traits'
34 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~~~~
p1572.cpp:17:27: note: original definition appeared here
17 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~~~~
p1572.cpp:62:32: error: expected ')' before '*' token
62 | basic_syncbuf(streambuf_type* obuf, const Allocator& allocator);
| ~ ^
| )
p1572.cpp:67:20: error: template placeholder type 'basic_syncbuf<...auto...>' must be followed by a simple declarator-id
67 | basic_syncbuf(basic_syncbuf&& other);
| ^~~~~~~~~~~~~
p1572.cpp:18:13: note: 'template<class charT, class traits, class Allocator> class std::basic_syncbuf' declared here
18 | class basic_syncbuf;
| ^~~~~~~~~~~~~
p1572.cpp:67:6: error: deduction guide for 'std::basic_syncbuf<charT, traits, Allocator>' must have trailing return type
67 | basic_syncbuf(basic_syncbuf&& other);
| ^~~~~~~~~~~~~
p1572.cpp:18:13: note: 'template<class charT, class traits, class Allocator> class std::basic_syncbuf' declared here
18 | class basic_syncbuf;
| ^~~~~~~~~~~~~
p1572.cpp:70:15: error: expected class-name before '(' token
70 | ~basic_syncbuf();
| ^
p1572.cpp:74:26: error: template placeholder type 'basic_syncbuf<...auto...>' must be followed by a simple declarator-id
74 | basic_syncbuf& operator=(basic_syncbuf&& rhs);
| ^~~~~~~~~~~~~
p1572.cpp:18:13: note: 'template<class charT, class traits, class Allocator> class std::basic_syncbuf' declared here
18 | class basic_syncbuf;
| ^~~~~~~~~~~~~
p1572.cpp:74:1: error: deduced class type 'basic_syncbuf' in function return type
74 | basic_syncbuf& operator=(basic_syncbuf&& rhs);
| ^~~~~~~~~~~~~
p1572.cpp:18:13: note: 'template<class charT, class traits, class Allocator> class std::basic_syncbuf' declared here
18 | class basic_syncbuf;
| ^~~~~~~~~~~~~
p1572.cpp:79:11: error: template placeholder type 'basic_syncbuf<...auto...>' must be followed by a simple declarator-id
79 | void swap(basic_syncbuf& other);
| ^~~~~~~~~~~~~
p1572.cpp:18:13: note: 'template<class charT, class traits, class Allocator> class std::basic_syncbuf' declared here
18 | class basic_syncbuf;
| ^~~~~~~~~~~~~
p1572.cpp:93:1: error: 'allocator_type' does not name a type
93 | allocator_type get_allocator() const noexcept;
| ^~~~~~~~~~~~~~
p1572.cpp:98:12: error: virt-specifiers in 'sync' not allowed outside a class definition
98 | int sync() override;
| ^~~~~~~~
p1572.cpp:98:5: error: ambiguating new declaration of 'int sync()'
98 | int sync() override;
| ^~~~
In file included from /usr/local/include/c++/12.1.0/bits/atomic_wait.h:44,
from /usr/local/include/c++/12.1.0/bits/atomic_base.h:41,
from /usr/local/include/c++/12.1.0/atomic:41,
from N4910.h:11,
from p1572.cpp:10:
/usr/include/unistd.h:970:13: note: old declaration 'void sync()'
970 | extern void sync (void) __THROW;
| ^~~~
p1572.cpp:109:25: error: redefinition of default argument for 'class traits'
109 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~~~~
p1572.cpp:25:27: note: original definition appeared here
25 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
| ^~~~~
p1572.cpp: In function 'void sample3()':
p1572.cpp:143:22: error: variable 'std::osyncstream bout' has initializer but incomplete type
143 | osyncstream bout(cout);
| ^
p1572.cpp:149:17: error: invalid use of incomplete type 'using osyncstream = class std::basic_osyncstream<char>' {aka 'class std::basic_osyncstream<char>'}
149 | osyncstream(cout) << "Hello, " << "World!" << '\n';
| ^
p1572.cpp:26:13: note: declaration of 'using osyncstream = class std::basic_osyncstream<char>' {aka 'class std::basic_osyncstream<char>'}
26 | class basic_osyncstream;
| ^~~~~~~~~~~~~~~~~
p1572.cpp:152:22: error: 'streambuf_type' was not declared in this scope
152 | basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
| ^~~~~~~~~~~~~~
p1572.cpp:152:38: error: 'buf' was not declared in this scope
152 | basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
| ^~~
p1572.cpp:152:21: error: missing template arguments before '(' token
152 | basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
| ^
p1572.cpp:152:43: error: expected primary-expression before 'const'
152 | basic_osyncstream(streambuf_type* buf, const Allocator& allocator);
| ^~~~~
p1572.cpp: At global scope:
p1572.cpp:158:6: error: ambiguating new declaration of 'void emit()'
158 | void emit();
| ^~~~
p1572.cpp:83:6: note: old declaration 'bool emit()'
83 | bool emit();
| ^~~~
p1572.cpp:161:1: error: 'bout' does not name a type
161 | bout << "Greetings." << '\n';
| ^~~~
p1572.cpp:163:22: error: variable 'std::osyncstream bout' has initializer but incomplete type
163 | osyncstream bout(cout);
| ^
p1572.cpp:164:1: error: 'bout' does not name a type
164 | bout << "Hello," << '\n';
| ^~~~
p1572.cpp:165:1: error: 'bout' does not name a type
165 | bout.emit();
| ^~~~
p1572.cpp:166:1: error: 'bout' does not name a type
166 | bout << "World!" << endl;
| ^~~~
p1572.cpp:167:1: error: 'bout' does not name a type
167 | bout.emit();
| ^~~~
p1572.cpp: In function 'void sample()':
p1572.cpp:175:26: error: variable 'std::osyncstream bout' has initializer but incomplete type
175 | osyncstream bout(cout);
| ^
p1572.cpp: At global scope:
p1572.cpp:182:1: error: 'streambuf_type' does not name a type
182 | streambuf_type* get_wrapped() const noexcept;
| ^~~~~~~~~~~~~~
p1572.cpp: In function 'void sample2()':
p1572.cpp:186:32: error: variable 'std::osyncstream bout1' has initializer but incomplete type
186 | osyncstream bout1(cout);
| ^
p1572.cpp:189:43: error: invalid use of incomplete type 'using osyncstream = class std::basic_osyncstream<char>' {aka 'class std::basic_osyncstream<char>'}
189 | osyncstream(bout1.get_wrapped()) << "Goodbye, " << "Planet!" << '\n';
| ^
p1572.cpp:26:13: note: declaration of 'using osyncstream = class std::basic_osyncstream<char>' {aka 'class std::basic_osyncstream<char>'}
26 | class basic_osyncstream;
| ^~~~~~~~~~~~~~~~~
検討事項(agenda)
コンパイルエラーを取るか、コンパイルエラーの理由を解説する。
応用例1 AUTOSAR C++
AUTOSARでC++のコーディング標準を作っている。
MISRA-C++コーディング標準の改訂をまたずに、C++14に対応したかったためかもしれない。
Autosar Guidelines C++14 example code compile list
MISRA C++, AUTOSAR C++について
応用例2 MISRA C/C++
MISRA C まとめ #include
MISRA C++ 5-0-16
応用例3 CERT C/C++
SEI CERT C++ Coding Standard AA. Bibliography 確認中。
MISRA C/C++, AUTOSAR C++, CERT C/C++とC/C++工業標準をコンパイルする
応用例4 箱庭
箱庭もくもく会 #10 日時:2022/09/14(水) 17:30-19:30
箱庭ではUnityをはじめC++を使っているらしい。
ここでコンパイルしたコードと同じようなコードを使っているか、
ここで出たコンパイルエラーと同じようなエラーがでたかを
いろいろな版のコンパイラでコンパイルして確認していく。
この項目は、箱庭プロジェクトを市場分析の対象として、原則的には、箱庭プロジェクトの外部から分析し、外部から箱庭の広告宣伝のための戦略会議を仮想した結果、仮想「箱庭もくもく会」を開催してみることを企画するものである。
一切の内容は、箱庭プロジェクト、Athrill, TOPPERSとは無関係である。
一(いち)参加データアナリストの、個人的なつぶやきです。
仮想戦略会議「箱庭」
お盆には「箱庭」記事を書きましょう「もくもく会」の題材になる(1)
お盆には「箱庭」記事を書きましょう「もくもく会」の題材になる(2)
自己参考資料(self reference)
関連する自己参照以外は、こちらの先頭に移転。
C言語(C++)に対する誤解、曲解、無理解、爽快。
#include "N4910.h"
C++N4910資料の改善点
dockerにclang
docker gnu(gcc/g++) and llvm(clang/clang++)
コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
C++N4910:2022 tag follower 300人超えました。ありがとうございます。
astyle 使ってみた
<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
文書履歴(document history)
ver. 0.01 初稿 20220902