lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Safer is the Yoda style?


From: Greg Chicares
Subject: [lmi] Safer is the Yoda style?
Date: Sun, 9 Jun 2019 21:17:24 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

When writing an assertion, I experimentally deviated from the "Yoda"
style, to see whether gcc would flag the error. It didn't. Do other
compilers diagnose the mistake in the simplified testcase below (where
the defect is more obvious than in the actual code I was writing)?

---------8<--------8<--------8<--------8<--------8<--------8<--------8<-------
diff --git a/sandbox_test.cpp b/sandbox_test.cpp
index bbc998e0..0da06a8d 100644
--- a/sandbox_test.cpp
+++ b/sandbox_test.cpp
@@ -23,7 +23,14 @@
 
 #include "test_tools.hpp"
 
-int test_main(int, char*[])
+#include <cassert>
+
+int test_main(int argc, char*[])
 {
+    std::cout << "argc is " << argc << std::endl;
+    assert(argc = -1);
+    assert(argc = -2);
+    assert(argc = -3);
+    std::cout << "All assertions succeeded." << std::endl;
     return 0;
 }
--------->8-------->8-------->8-------->8-------->8-------->8-------->8-------

$ make unit_tests unit_test_targets=sandbox_test.exe

i686-w64-mingw32-g++ -MMD -MP -MT sandbox_test.o -MF sandbox_test.d  -c -I 
/opt/lmi/src/lmi -I /opt
/lmi/src/lmi/tools/pete-2.1.1 -I 
/opt/lmi/local/gcc_i686-w64-mingw32/lib/wx/include/i686-w64-mingw3
2-msw-unicode-3.1 -I /opt/lmi/local/include/wx-3.1 -I 
/opt/lmi/third_party/include -I /opt/lmi/thir
d_party/src -I /opt/lmi/local/include -I /opt/lmi/local/include/libxml2 
-DLMI_WX_NEW_USE_SO  -DLIBX
ML_USE_DLL -DSTRICT    -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__ 
-D_FILE_OFFSET_BITS=64 -DBOO
ST_NO_AUTO_PTR -DBOOST_STRICT_CONFIG -DBOOST_STATIC_ASSERT_HPP   
-frounding-math -std=c++17 -pedantic-errors -Werror -Wall -Walloc-zero -Walloca 
-Wcast-align -Wconversion -Wdangling-else -Wdeprecated-declarations 
-Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches 
-Wduplicated-cond -Wextra -Wformat-nonliteral -Wformat-security 
-Wformat-signedness -Wformat-y2k -Wimport -Winit-self -Winvalid-pch 
-Wlogical-op -Wmissing-include-dirs -Wmultichar -Wnull-dereference -Wpacked 
-Wpointer-arith -Wredundant-decls -Wrestrict -Wshadow -Wsign-compare 
-Wstack-protector -Wswitch-enum -Wtrampolines -Wundef -Wunreachable-code 
-Wunused-macros -Wvector-operation-performance -Wwrite-strings -Wno-parentheses 
 -Wc++11-compat -Wc++14-compat -Wc++1z-compat -Wconditionally-supported 
-Wctor-dtor-privacy -Wdelete-non-virtual-dtor -Wdeprecated -Wnoexcept 
-Wnoexcept-type -Wnon-template-friend -Wnon-virtual-dtor -Woverloaded-virtual 
-Wpmf-conversions -Wregister -Wreorder -Wstrict-null-sentinel -Wsynth 
-Wuseless-cast  -Wcast-qual    -D'BOOST_STATIC_ASSERT(A)=static_assert((A))'   
-ggdb -O2 -fno-omit-frame-pointer    /opt/lmi/src/lmi/sandbox_test.cpp 
-osandbox_test.o
i686-w64-mingw32-g++ -o sandbox_test.exe alert.o alert_cli.o fenv_lmi.o 
getopt.o license.o sandbox_test.o -L . -L 
/opt/lmi/local/gcc_i686-w64-mingw32/lib -L 
/opt/lmi/local/gcc_i686-w64-mingw32/bin    -lexslt -lxslt -lxml2      
-Wl,-Map,sandbox_test.exe.map

Running sandbox_test:
argc is 2
All assertions succeeded.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]