diff --git a/HACKING b/HACKING index f4c09f00a..76bc86509 100644 --- a/HACKING +++ b/HACKING @@ -554,6 +554,37 @@ Naming * Use *.hxx for the implementation of templates that are private to Spot (i.e., not installed) and need to be included multiple times. +SPOT macros +----------- + + A few macros are defined in misc/common.hh notably: + + * SPOT_FALLTHROUGH should be used to mark fall-throughs in switches: + + switch (foo) + { + case 1: + f(); + SPOT_FALLTHROUGH; + case 2: + g(); + break; + } + + * Use SPOT_UNREACHABLE() to mark places that are not reachable but + that a compiler might not see as unreachable. + + * Use SPOT_API in front of functions and class that should be + exported by the shared library. See "Exporting symbolss" above. + + * Use SPOT_ASSERT(...) if you ever have to put an assertion in + some header file. See "Assertions" above. + + * Use SPOT_LIKELY / SPOT_UNLIKELY in case you need to help the + compiler figure out the commont output of a test. Do not abuse + this without checking the assembly output to make sure the effect + is what you desired. + Other style recommandations --------------------------- diff --git a/NEWS b/NEWS index a13144d36..66645c547 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,8 @@ New in spot 2.1.1.dev (not yet released) should flush std::cout; however it was well visible when reading from files. Flushing is now done more regularly. + - Fix compilation warnings when -Wimplicit-fallthrough it enabled. + New in spot 2.1.1 (2016-09-20) Command-line tools: diff --git a/bin/randltl.cc b/bin/randltl.cc index fbff92935..2f7970e19 100644 --- a/bin/randltl.cc +++ b/bin/randltl.cc @@ -289,7 +289,7 @@ main(int argc, char** argv) std::cout << "Use --ltl-priorities to set the following LTL priorities:\n"; rg.dump_psl_priorities(std::cout); - // Fall through. + SPOT_FALLTHROUGH; case OUTPUTSERE: std::cout << "Use --sere-priorities to set the following SERE priorities:\n"; diff --git a/spot/misc/common.hh b/spot/misc/common.hh index 83d5c4a31..4402229a4 100644 --- a/spot/misc/common.hh +++ b/spot/misc/common.hh @@ -117,6 +117,20 @@ // auto func(int param) SPOT_RETURN(implem_.func(param)); #define SPOT_RETURN(code) -> decltype(code) { return code; } +// We hope compilers that implement -Wimplicit-fallthrough +// also support __has_cpp_attribute and some form of [[fallthrough]]. +#ifdef __has_cpp_attribute +# if __has_cpp_attribute(fallthrough) +# define SPOT_FALLTHROUGH [[fallthrough]] +# elif __has_cpp_attribute(clang::fallthrough) +# define SPOT_FALLTHROUGH [[clang::fallthrough]] +# elif __has_cpp_attribute(gcc::fallthrough) +# define SPOT_FALLTHROUGH [[gcc::fallthrough]] +# endif +#endif +#ifndef SPOT_FALLTHROUGH +# define SPOT_FALLTHROUGH while (0) +#endif namespace spot { diff --git a/spot/misc/escape.cc b/spot/misc/escape.cc index b9035a185..2ec8d622c 100644 --- a/spot/misc/escape.cc +++ b/spot/misc/escape.cc @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2012, 2013, 2015 Laboratoire de Recherche et Developpement de -// l'Epita (LRDE) +// Copyright (C) 2012, 2013, 2015, 2016 Laboratoire de Recherche et +// Developpement de l'Epita (LRDE) // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre // et Marie Curie. @@ -67,6 +67,7 @@ namespace spot case '{': case '}': os << '\\'; + SPOT_FALLTHROUGH; default: os << i; break; @@ -149,7 +150,7 @@ namespace spot case '"': case '\\': os << '\\'; - // fall through + SPOT_FALLTHROUGH; default: os << *str++; break; diff --git a/spot/tl/mutation.cc b/spot/tl/mutation.cc index ed4c51ccd..2c04dd510 100644 --- a/spot/tl/mutation.cc +++ b/spot/tl/mutation.cc @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2014, 2015 Laboratoire de Recherche et Developpement de -// l'Epita (LRDE). +// Copyright (C) 2014, 2015, 2016 Laboratoire de Recherche et +// Developpement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -85,7 +85,7 @@ namespace spot if ((opts_ & Mut_Remove_Ops) && mutation_counter_-- == 0) return f[0]; - // fall through + SPOT_FALLTHROUGH; case op::Closure: case op::NegClosure: case op::NegClosureMarked: diff --git a/spot/tl/print.cc b/spot/tl/print.cc index ad55a93b6..06fb49d19 100644 --- a/spot/tl/print.cc +++ b/spot/tl/print.cc @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2008, 2010, 2012, 2013, 2014, 2015 Laboratoire de +// Copyright (C) 2008, 2010, 2012, 2013, 2014, 2015, 2016 Laboratoire de // Recherche et Développement de l'Epita (LRDE) // Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // département Systèmes Répartis Coopératifs (SRC), Université Pierre @@ -527,7 +527,7 @@ namespace spot emit(KNot); if (o == op::NegClosureMarked) os_ << (kw_ == utf8_kw ? "̃": "+"); - // Fall through + SPOT_FALLTHROUGH; case op::Closure: os_ << '{'; in_ratexp_ = true; diff --git a/spot/tl/simplify.hh b/spot/tl/simplify.hh index 2af118f81..c2f6a3c36 100644 --- a/spot/tl/simplify.hh +++ b/spot/tl/simplify.hh @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2011, 2012, 2013, 2014, 2015 Laboratoire de Recherche -// et Developpement de l'Epita (LRDE). +// Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016 Laboratoire de +// Recherche et Developpement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -58,14 +58,14 @@ namespace spot case 3: containment_checks = true; containment_checks_stronger = true; - // fall through + SPOT_FALLTHROUGH; case 2: synt_impl = true; - // fall through + SPOT_FALLTHROUGH; case 1: reduce_basics = true; event_univ = true; - // fall through + SPOT_FALLTHROUGH; default: break; } diff --git a/spot/tl/snf.cc b/spot/tl/snf.cc index 0fe79ff41..e234a44d2 100644 --- a/spot/tl/snf.cc +++ b/spot/tl/snf.cc @@ -19,6 +19,11 @@ #include +#if defined __clang__ +// See https://llvm.org/bugs/show_bug.cgi?id=30636 +#pragma clang diagnostic ignored "-Wimplicit-fallthrough" +#endif + namespace spot { namespace @@ -65,7 +70,7 @@ namespace spot out = f; break; } - // Fall through + SPOT_FALLTHROUGH; case op::OrRat: case op::AndNLM: // Let F designate expressions that accept [*0], diff --git a/spot/twa/acc.cc b/spot/twa/acc.cc index 44a688d6f..407711c14 100644 --- a/spot/twa/acc.cc +++ b/spot/twa/acc.cc @@ -77,6 +77,7 @@ namespace spot { case acc_cond::acc_op::And: op = html ? " & " : " & "; + SPOT_FALLTHROUGH; case acc_cond::acc_op::Or: { unsigned sub = pos - w.size; @@ -99,6 +100,7 @@ namespace spot break; case acc_cond::acc_op::InfNeg: negated = "!"; + SPOT_FALLTHROUGH; case acc_cond::acc_op::Inf: { auto a = code[pos - 1].mark.id; @@ -134,6 +136,7 @@ namespace spot break; case acc_cond::acc_op::FinNeg: negated = "!"; + SPOT_FALLTHROUGH; case acc_cond::acc_op::Fin: { auto a = code[pos - 1].mark.id; @@ -347,6 +350,7 @@ namespace spot pos -= 2; break; } + SPOT_FALLTHROUGH; case acc_cond::acc_op::FinNeg: return true; } @@ -1017,7 +1021,7 @@ namespace spot case acc_cond::acc_op::FinNeg: if (pos[-1].mark.count() > 1 && pos > and_scope) return false; - /* fall through */ + SPOT_FALLTHROUGH; case acc_cond::acc_op::Inf: case acc_cond::acc_op::InfNeg: pos -= 2; @@ -1050,7 +1054,7 @@ namespace spot case acc_cond::acc_op::InfNeg: if (pos[-1].mark.count() > 1 && pos > or_scope) return false; - /* fall through */ + SPOT_FALLTHROUGH; case acc_cond::acc_op::Fin: case acc_cond::acc_op::FinNeg: pos -= 2; diff --git a/spot/twaalgos/ltl2taa.cc b/spot/twaalgos/ltl2taa.cc index a83bb0833..fcb06373a 100644 --- a/spot/twaalgos/ltl2taa.cc +++ b/spot/twaalgos/ltl2taa.cc @@ -154,7 +154,7 @@ namespace spot { case op::U: strong = true; - // fall thru + SPOT_FALLTHROUGH; case op::W: if (refined_) contained = lcc_->contained(f[0], f[1]); @@ -186,6 +186,7 @@ namespace spot return; case op::M: // Strong Release strong = true; + SPOT_FALLTHROUGH; case op::R: // Weak Release if (refined_) contained = lcc_->contained(f[0], f[1]); diff --git a/spot/twaalgos/ltl2tgba_fm.cc b/spot/twaalgos/ltl2tgba_fm.cc index 0c006ec93..93af563d0 100644 --- a/spot/twaalgos/ltl2tgba_fm.cc +++ b/spot/twaalgos/ltl2tgba_fm.cc @@ -1264,6 +1264,7 @@ namespace spot } case op::NegClosureMarked: has_marked_ = true; + SPOT_FALLTHROUGH; case op::NegClosure: rat_seen_ = true; { @@ -1394,7 +1395,7 @@ namespace spot } case op::EConcatMarked: has_marked_ = true; - /* fall through */ + SPOT_FALLTHROUGH; case op::EConcat: rat_seen_ = true; { diff --git a/spot/twaalgos/sepsets.cc b/spot/twaalgos/sepsets.cc index ff176a531..fbb2a7fb6 100644 --- a/spot/twaalgos/sepsets.cc +++ b/spot/twaalgos/sepsets.cc @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2015 Laboratoire de Recherche et -// Développement de l'Epita. +// Copyright (C) 2015, 2016 Laboratoire de Recherche et Développement +// de l'Epita. // // This file is part of Spot, a model checking library. // @@ -76,7 +76,7 @@ namespace spot pos[-1].mark -= p.first; pos[-1].mark |= p.second; } - /* fall through */ + SPOT_FALLTHROUGH; case acc_cond::acc_op::Inf: case acc_cond::acc_op::InfNeg: pos -= 2; diff --git a/spot/twaalgos/translate.cc b/spot/twaalgos/translate.cc index f4b093332..4ec085524 100644 --- a/spot/twaalgos/translate.cc +++ b/spot/twaalgos/translate.cc @@ -1,6 +1,6 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2013, 2014, 2015 Laboratoire de Recherche et Développement -// de l'Epita (LRDE). +// Copyright (C) 2013, 2014, 2015, 2016 Laboratoire de Recherche et +// Développement de l'Epita (LRDE). // // This file is part of Spot, a model checking library. // @@ -49,14 +49,13 @@ namespace spot case High: options.containment_checks = true; options.containment_checks_stronger = true; - // fall through + SPOT_FALLTHROUGH; case Medium: options.synt_impl = true; - // fall through + SPOT_FALLTHROUGH; case Low: options.reduce_basics = true; options.event_univ = true; - // fall through } simpl_owned_ = simpl_ = new tl_simplifier(options, dict); }