Re: [Boost-bugs] [Boost C++ Libraries] #8665: Unreachable code warnings in variant.hpp - msvc

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #8665: Unreachable code warnings in variant.hpp - msvc
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-09-06 15:03:18

#8665: Unreachable code warnings in variant.hpp - msvc
  Reporter: hvemha@… | Owner: ebf
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: variant
   Version: Boost 1.53.0 | Severity: Problem
Resolution: | Keywords:

Comment (by hvemha@…):

 The warning on line 1017 is supressed by defining NDEBUG (adding /D NDEBUG
 to the command line). I’m not too concerned about this as NDEBUG should be
 defined when creating optimized builds.

 I used the same version (now on update 3). The warning is also produced by
 earlier versions of the VC.

 This simple code will produce the warning:

 void no_return() {}

 int call_no_return() { no_return(); }

 int main(int argc, char**)
         if( argc > 0 )
                 return call_no_return(); // warning C4702
         return 7;

 I guess the warning is related to assigning the return value of
 {{{call_no_return}}} to a variable in main scope (in an intermediate
 compiler language?), and not the function call.

 Looking at the machine code it looks like the optimizer will assume the
 function never returns when declared with {{{__declspec(noreturn)}}}. The
 optimizer change the above code to {{{"return 7;"}}}, but if a side effect
 is introduces into {{{no_return}}}, the behaviour is undefined (typically
 a crash when returning from {{{no_return}}} as the compiler has not
 included the required instructions). In non-optimized builds the compiler
 ignores the {{{noreturn}}} declaration and generates instructions as if
 the function will/can return.

 In my opinion the compiler is correct to issue the warning (the programmer
 has told the compiler that the function will not return).

 Note: the fact that the compiler changes my example code to {{{"return
 7;"}}} is also OK as for {{{argc > 0}}} the behaviour is undefined...

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:14 UTC