From a82aeedb5b9e24c9788febab3dcf65169b79cece Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Sat, 24 Feb 2024 15:52:16 -0800 Subject: [PATCH] Warn on implicit switch case fallthrough This seems to have found one actual bug in fs-sink.cc: the symlink case was falling into the regular file case, which can't possibly be intentional, right? --- Makefile | 2 +- src/libexpr/lexer.l | 3 +++ src/libutil/fs-sink.cc | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d3542c3e981..f8689c8cff2 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ ifdef HOST_WINDOWS GLOBAL_LDFLAGS += -Wl,--export-all-symbols endif -GLOBAL_CXXFLAGS += -g -Wall -include $(buildprefix)config.h -std=c++2a -I src +GLOBAL_CXXFLAGS += -g -Wall -Wimplicit-fallthrough -include $(buildprefix)config.h -std=c++2a -I src # Include the main lib, causing rules to be defined diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 380048c77e2..5b26d6927de 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -94,6 +94,9 @@ static StringToken unescapeStr(SymbolTable & symbols, char * s, size_t length) } +// yacc generates code that uses unannotated fallthrough. +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" + #define YY_USER_INIT initLoc(yylloc) #define YY_USER_ACTION adjustLoc(yylloc, yytext, yyleng); diff --git a/src/libutil/fs-sink.cc b/src/libutil/fs-sink.cc index 95b6088da9e..35ce0ac3611 100644 --- a/src/libutil/fs-sink.cc +++ b/src/libutil/fs-sink.cc @@ -15,6 +15,7 @@ void copyRecursive( case SourceAccessor::tSymlink: { sink.createSymlink(to, accessor.readLink(from)); + break; } case SourceAccessor::tRegular: @@ -38,6 +39,7 @@ void copyRecursive( sink, to + "/" + name); break; } + break; } case SourceAccessor::tMisc: