lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master f397d96 3/3: Add [[noreturn]] where 'gcc -Wsu


From: Greg Chicares
Subject: [lmi-commits] [lmi] master f397d96 3/3: Add [[noreturn]] where 'gcc -Wsuggest-attribute=noreturn' suggests
Date: Fri, 10 Mar 2017 14:14:48 -0500 (EST)

branch: master
commit f397d963fb5575e1f29057ae71b45e272a9494ab
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Add [[noreturn]] where 'gcc -Wsuggest-attribute=noreturn' suggests
    
    See:
      http://lists.nongnu.org/archive/html/lmi/2017-03/msg00065.html
    
    Function alarum() correctly does not have the [[noreturn]] attribute
    because merely calling it does not throw an exception; an exception is
    thrown when the ostream it returns is flushed.
    
    alarum_buf::raise_alert() was given the [[noreturn]] attribute even
    though gcc did not suggest it. This is logically required: every
    function that can appropriately be assigned to *alarum_alert_function
    has attribute [[noreturn]]. An explicit throw-expression was added to
    prevent gcc from warning that this function appeared to return.
    
    Incidentally, these warning options
      -Wsuggest-attribute=pure
      -Wsuggest-attribute=const
    produced no diagnostics.
---
 alert.cpp                | 4 ++++
 alert_cgi.cpp            | 3 +++
 alert_cli.cpp            | 1 +
 alert_wx.cpp             | 1 +
 any_member.hpp           | 1 +
 dbdict.cpp               | 8 ++++++--
 mortality_rates_test.cpp | 1 +
 round_to.hpp             | 1 +
 rounding_rules.cpp       | 8 ++++++--
 skeleton.cpp             | 2 ++
 stratified_charges.cpp   | 8 ++++++--
 xml_serializable.tpp     | 2 ++
 12 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/alert.cpp b/alert.cpp
index 10729b3..6a06970 100644
--- a/alert.cpp
+++ b/alert.cpp
@@ -178,9 +178,11 @@ class hobsons_choice_buf
 class alarum_buf
     :public alert_buf
 {
+    [[noreturn]]
     void raise_alert() override
         {
         alarum_alert_function(alert_string());
+        throw "This should be unreachable--something is gravely amiss.";
         }
 };
 
@@ -265,11 +267,13 @@ void test_alarum()
     alarum()         << "Test alarum()"         << LMI_FLUSH;
 }
 
+[[noreturn]]
 void test_standard_exception()
 {
     throw std::runtime_error("Test a standard exception.");
 }
 
+[[noreturn]]
 void test_arbitrary_exception()
 {
     throw "Test an arbitrary exception.";
diff --git a/alert_cgi.cpp b/alert_cgi.cpp
index b105ec0..598bd1e 100644
--- a/alert_cgi.cpp
+++ b/alert_cgi.cpp
@@ -47,16 +47,19 @@ void status_alert(std::string const&)
 // a higher-level routine catch and display it. It might be desirable
 // to write a log file, too.
 
+[[noreturn]]
 void warning_alert(std::string const& s)
 {
     throw std::runtime_error(s);
 }
 
+[[noreturn]]
 void hobsons_choice_alert(std::string const& s)
 {
     throw std::runtime_error(s);
 }
 
+[[noreturn]]
 void alarum_alert(std::string const& s)
 {
     throw std::runtime_error(s);
diff --git a/alert_cli.cpp b/alert_cli.cpp
index 39c4076..c64f60e 100644
--- a/alert_cli.cpp
+++ b/alert_cli.cpp
@@ -96,6 +96,7 @@ void hobsons_choice_alert(std::string const& s)
         }
 }
 
+[[noreturn]]
 void alarum_alert(std::string const& s)
 {
     throw std::runtime_error(s);
diff --git a/alert_wx.cpp b/alert_wx.cpp
index 2eabf58..fb78f69 100644
--- a/alert_wx.cpp
+++ b/alert_wx.cpp
@@ -115,6 +115,7 @@ void hobsons_choice_alert(std::string const& s)
         }
 }
 
+[[noreturn]]
 void alarum_alert(std::string const& s)
 {
     throw std::runtime_error(s);
diff --git a/any_member.hpp b/any_member.hpp
index 7035764..c04665a 100644
--- a/any_member.hpp
+++ b/any_member.hpp
@@ -567,6 +567,7 @@ MemberSymbolTable<ClassType>::~MemberSymbolTable() = 
default;
 // addition is attempted.
 
 template<typename ClassType>
+[[noreturn]]
 void MemberSymbolTable<ClassType>::complain_that_no_such_member_is_ascribed
     (std::string const& name
     ) const
diff --git a/dbdict.cpp b/dbdict.cpp
index a08408e..5c81d7f 100644
--- a/dbdict.cpp
+++ b/dbdict.cpp
@@ -66,7 +66,9 @@ template<> struct xml_io<database_entity>
 ///   any_member::str()
 /// which is not useful here.
 
-template<> std::string value_cast<std::string>(database_entity const&)
+template<>
+[[noreturn]]
+std::string value_cast<std::string>(database_entity const&)
 {
     alarum() << "Invalid function call." << LMI_FLUSH;
     throw "Unreachable--silences a compiler diagnostic.";
@@ -78,7 +80,9 @@ template<> std::string 
value_cast<std::string>(database_entity const&)
 ///   any_member::operator=(std::string const&)
 /// which is not useful here.
 
-template<> database_entity value_cast<database_entity>(std::string const&)
+template<>
+[[noreturn]]
+database_entity value_cast<database_entity>(std::string const&)
 {
     alarum() << "Invalid function call." << LMI_FLUSH;
     throw "Unreachable--silences a compiler diagnostic.";
diff --git a/mortality_rates_test.cpp b/mortality_rates_test.cpp
index dc6c6f7..b71b565 100644
--- a/mortality_rates_test.cpp
+++ b/mortality_rates_test.cpp
@@ -76,6 +76,7 @@ std::vector<double> monthly_rates()
 }
 } // Unnamed namespace.
 
+[[noreturn]]
 void MortalityRates::fetch_parameters(BasicValues const&) {throw "Error";}
 
 MortalityRates::MortalityRates()
diff --git a/round_to.hpp b/round_to.hpp
index 63814d3..624b69d 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -272,6 +272,7 @@ RealType round_near(RealType r)
 }
 
 template<typename RealType>
+[[noreturn]]
 RealType erroneous_rounding_function(RealType)
 {
     throw std::logic_error("Erroneous rounding function.");
diff --git a/rounding_rules.cpp b/rounding_rules.cpp
index 7f66e8d..f541207 100644
--- a/rounding_rules.cpp
+++ b/rounding_rules.cpp
@@ -65,7 +65,9 @@ template<> struct xml_io<rounding_parameters>
 ///   any_member::str()
 /// which is not useful here.
 
-template<> std::string value_cast<std::string>(rounding_parameters const&)
+template<>
+[[noreturn]]
+std::string value_cast<std::string>(rounding_parameters const&)
 {
     alarum() << "Invalid function call." << LMI_FLUSH;
     throw "Unreachable--silences a compiler diagnostic.";
@@ -77,7 +79,9 @@ template<> std::string 
value_cast<std::string>(rounding_parameters const&)
 ///   any_member::operator=(std::string const&)
 /// which is not useful here.
 
-template<> rounding_parameters value_cast<rounding_parameters>(std::string 
const&)
+template<>
+[[noreturn]]
+rounding_parameters value_cast<rounding_parameters>(std::string const&)
 {
     alarum() << "Invalid function call." << LMI_FLUSH;
     throw "Unreachable--silences a compiler diagnostic.";
diff --git a/skeleton.cpp b/skeleton.cpp
index 5bfcb07..bcddd1f 100644
--- a/skeleton.cpp
+++ b/skeleton.cpp
@@ -948,11 +948,13 @@ void Skeleton::UponTestAppFatal(wxCommandEvent&)
     alarum()         << "Test alarum() ."         << LMI_FLUSH;
 }
 
+[[noreturn]]
 void Skeleton::UponTestAppStandardException(wxCommandEvent&)
 {
     throw std::runtime_error("Test a standard exception.");
 }
 
+[[noreturn]]
 void Skeleton::UponTestAppArbitraryException(wxCommandEvent&)
 {
     throw "Test an arbitrary exception.";
diff --git a/stratified_charges.cpp b/stratified_charges.cpp
index 11e4bf9..411f4b0 100644
--- a/stratified_charges.cpp
+++ b/stratified_charges.cpp
@@ -62,7 +62,9 @@ namespace xml_serialize
 ///   any_member::str()
 /// which is not useful here.
 
-template<> std::string value_cast<std::string>(stratified_entity const&)
+template<>
+[[noreturn]]
+std::string value_cast<std::string>(stratified_entity const&)
 {
     alarum() << "Invalid function call." << LMI_FLUSH;
     throw "Unreachable--silences a compiler diagnostic.";
@@ -74,7 +76,9 @@ template<> std::string 
value_cast<std::string>(stratified_entity const&)
 ///   any_member::operator=(std::string const&)
 /// which is not useful here.
 
-template<> stratified_entity value_cast<stratified_entity>(std::string const&)
+template<>
+[[noreturn]]
+stratified_entity value_cast<stratified_entity>(std::string const&)
 {
     alarum() << "Invalid function call." << LMI_FLUSH;
     throw "Unreachable--silences a compiler diagnostic.";
diff --git a/xml_serializable.tpp b/xml_serializable.tpp
index 5f65b13..9bcfd90 100644
--- a/xml_serializable.tpp
+++ b/xml_serializable.tpp
@@ -187,6 +187,7 @@ void xml_serializable<T>::immit_members_into(xml::element& 
root) const
 /// Backward-compatibility serial number of class T's xml version.
 
 template<typename T>
+[[noreturn]]
 int xml_serializable<T>::class_version() const
 {
     throw "Unreachable--silences a compiler diagnostic.";
@@ -195,6 +196,7 @@ int xml_serializable<T>::class_version() const
 /// Root tag (when T is saved as the root of a document).
 
 template<typename T>
+[[noreturn]]
 std::string const& xml_serializable<T>::xml_root_name() const
 {
     throw "Unreachable--silences a compiler diagnostic.";



reply via email to

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