https://www.oreilly.co.jp/books/9784873117362/
ソースコードをコンパイル、実行しながら考える。
https://github.com/BartVandewoestyne/Effective-Modern-Cpp
ダウンロードして、フォルダで
$ cmake CMakeLists.txt
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Boost version: 1.67.0
-- Configuring done
-- Generating done
-- Build files have been written to:
/tmp/effective-modern-cpp-master
$ make
警告はあまりない。
出力はない。
これでは、コンパイルしても嬉しくない。
-Wallで警告を出してみて、一覧する。
reference to stack memory associated with local variable 'x' returned
item02
/effective-modern-cpp-master/Item03_Understand_decltype/return_statements_cpp14.cpp:19:11: warning:
reference to stack memory associated with local variable 'x' returned [-Wreturn-stack-address]
return (x); // decltype((x)) is int&, so f2 returns int&
^
#control reaches end of non-void function(1)
invisible_proxy_types
/effective-modern-cpp-master/Item06_Use_the_explicitly_typed_initializer_idiom_when_auto_deduces_undesired_types/invisible_proxy_types.cpp:21:1: warning:
control reaches end of non-void function [-Wreturn-type]
}
^
##control reaches end of non-void function(2)
template_example_templatized_cpp14
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item08_Prefer_nullptr_to_0_and_NULL/template_example_templatized_cpp14.cpp:18:73: warning:
control reaches end of non-void function [-Wreturn-type]
int f1(std::shared_ptr<Widget> sp) { std::cout << "f1" << std::endl; } // call these only when
^
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item08_Prefer_nullptr_to_0_and_NULL/template_example_templatized_cpp14.cpp:19:73: warning:
control reaches end of non-void function [-Wreturn-type]
double f2(std::unique_ptr<Widget> up) { std::cout << "f2" << std::endl; } // the appropriate
^
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item08_Prefer_nullptr_to_0_and_NULL/template_example_templatized_cpp14.cpp:20:56: warning:
control reaches end of non-void function [-Wreturn-type]
bool f3(void* ptr) { std::cout << "f3" << std::endl; } // mutex is locked
^
3 warnings generated.
##control reaches end of non-void function(3)
template_example_flat
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item08_Prefer_nullptr_to_0_and_NULL/template_example_flat.cpp:15:74: warning:
control reaches end of non-void function [-Wreturn-type]
int f1(std::shared_ptr<Widget> spw) { std::cout << "f1" << std::endl; } // call these only when
^
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item08_Prefer_nullptr_to_0_and_NULL/template_example_flat.cpp:16:74: warning:
control reaches end of non-void function [-Wreturn-type]
double f2(std::unique_ptr<Widget> upw) { std::cout << "f2" << std::endl; } // the appropriate
^
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item08_Prefer_nullptr_to_0_and_NULL/template_example_flat.cpp:17:57: warning:
control reaches end of non-void function [-Wreturn-type]
bool f3(Widget* pw) { std::cout << "f3" << std::endl; } // mutex is locked
^
3 warnings generated.
##control reaches end of non-void function(4)
template_example_templatized
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item08_Prefer_nullptr_to_0_and_NULL/template_example_templatized.cpp:19:73: warning:
control reaches end of non-void function [-Wreturn-type]
int f1(std::shared_ptr<Widget> sp) { std::cout << "f1" << std::endl; } // call these only when
^
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item08_Prefer_nullptr_to_0_and_NULL/template_example_templatized.cpp:20:73: warning:
control reaches end of non-void function [-Wreturn-type]
double f2(std::unique_ptr<Widget> up) { std::cout << "f2" << std::endl; } // the appropriate
^
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item08_Prefer_nullptr_to_0_and_NULL/template_example_templatized.cpp:21:56: warning:
control reaches end of non-void function [-Wreturn-type]
bool f3(void* ptr) { std::cout << "f3" << std::endl; } // mutex is locked
^
3 warnings generated.
#empty parentheses interpreted as a function declaration
empty_braces
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item07_Distinguish_between()_and_{}_when_creating_objects/empty_braces.cpp:42:12: warning:
empty parentheses interpreted as a function declaration [-Wvexing-parse]
Widget w3(); // most vexing parse! declares a function!
^~
/Users/ogawakiyoshi/Downloads/effective-modern-cpp-master/Item07_Distinguish_between()_and_{}_when_creating_objects/empty_braces.cpp:42:12: note:
remove parentheses to declare a variable
Widget w3(); // most vexing parse! declares a function!
^~
1 warning generated.
#no object file members in the library define global symbols(1)
item10
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: warning for library: libpointer_example.a the table of contents is empty (no object file members in the library define global symbols)
##no object file members in the library define global symbols(2)
Widget
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: warning for library: libWidget.a the table of contents is empty (no object file members in the library define global symbols)
##no object file members in the library define global symbols(3)
typical_errors
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: warning for library: libtypical_errors.a the table of contents is empty (no object file members in the library define global symbols)
##no object file members in the library define global symbols(4)
typical_errors_corrected
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: warning for library: libtypical_errors_corrected.a the table of contents is empty (no object file members in the library define global symbols)
##no object file members in the library define global symbols(5)
typical_errors_with_override_added
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: warning for library: libtypical_errors_with_override_added.a the table of contents is empty (no object file members in the library define global symbols)
#文書履歴
ver 0.10 初稿 20180512
ver 0.20 警告一覧追記 20180518
最後までおよみいただきありがとうございました。
いいね 💚、フォローをお願いします。
Thank you very much for reading to the last sentence.
Please press the like icon 💚 and follow me for your happy life.