[Insight-developers] Warning - possible candidate for noreturn attribute

Karthik Krishnan karthik.krishnan at kitware.com
Tue Mar 20 13:04:06 EST 2007


Thanks Mathieu, Bill,

Your patch has been committed .

/cvsroot/Insight/Insight/Code/Common/itkMacro.h,v  <--  itkMacro.h
new revision: 1.71; previous revision: 1.70
/cvsroot/Insight/Insight/Code/Common/itkImageSource.h,v  <--
itkImageSource.h
new revision: 1.54; previous revision: 1.53

I went with Bill so as to define a suffix, because its more appealing to the
eye.

Thanks
--
karthik

On 3/20/07, Bill Lorensen <bill.lorensen at gmail.com> wrote:
>
> Mathieu,
>
> Your patch is different from Karthik's. You include a ";", his does not.
>
> Another alternative would be to define a suffix.
>
>  /** On some compiler, functions that do not return (ex: exit(0)) must
>    * have the noreturn attribute. Otherwise, a warning is raised. Use
>    * that macro to avoid those warnings. GCC defines the attribute
>    * noreturn for versions 2.5 and higher.*/
>  #if defined(__GNUC__)
>  #  if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
>  #    define ITK_NO_RETURN \
>         __attribute__ ((noreturn))
>  #  endif
>  #else
>  #  define ITK_NO_RETURN
>  #endif
>
> Usage:
>
> void foo () ITK_NO_RETURN;
>
> void foo() ITK_NO_RETURN
> {
> body...
> }
>
>
> Bill
>
>
> On 3/20/07, Mathieu Coursolle <mcoursolle at rogue-research.com> wrote:
>
> > Hi,
> >
> > Thanks for the hint.
> >
> > So any objection of doing the same kind of macro for ITK?
> >
> > Here is a patch to do so.
> >
> > Thanks.
> >
> > Mathieu
> >
> > >Here's the macro boost defines for noreturn functions:
> > >
> > >https://boost-consulting.com:8443/trac/soc/browser/boost/soc/2006/
> > >coroutine/trunk/boost/coroutine/detail/noreturn.hpp?rev=1087
> > >
> > >#if defined(__GNUC__)
> > >#define BOOST_COROUTINE_NORETURN(function) \
> > > function __attribute__((__noreturn__)) \
> > >#elif defined (BOOST_MSVC)
> > >#define BOOST_COROUTINE_NORETURN(function) \
> > > __declspec(noreturn) function \
> > >#else
> > >//just for testing, remove the following error.
> > >#error no default
> > >#define BOOST_COROUTINE_NORETURN(function) \
> > > function
> > >#endif
> > >
> > >used as BOOST_COROUTINE_NORETURN( void foo() )
> > >{
> > > //body of foo
> > >}
> > >
> > >BTW __attribute__((noreturn)) seems to be supported on gnuc compilers
> > >since 2.4 ..
> > >
> > >--
> > >karthik
> > >
> > >On 3/19/07, Bill Lorensen < bill.lorensen at gmail.com> wrote:
> > >Mathieu,
> > >
> > >Is there a compiler flag to suppress that warning?
> > >
> > >Bill
> > >
> > >
> > >On 3/19/07, Mathieu Coursolle <mcoursolle at rogue-research.com > wrote:
> > >Hi,
> > >
> > >I currently use ITK in a XCode project on Mac OSX.
> > >When I include some ITK headers, I get the following
> > >warning:
> > >
> > >/Common/itkImageSource.txx: In member function 'void
> > >itk::ImageSource<TOutputImage>::ThreadedGenerateData(const typename
> > >TOutputImage::RegionType&, int) [with TOutputImage = ITK2DImage]':
> > >/Common/itkImageSource.txx:244: warning: function might be possible
> > >candidate for attribute 'noreturn'
> > >
> > >This is cause by the fact that the implementation of
> > ThreadedGenerateData
> > >from itkImageSource (base class) just throws an exception, so it does
> > >not return.
> > >
> > >//----------------------------------
> > ------------------------------------------
> > >// The execute method created by the subclass.
> > >template <class TOutputImage>
> > >void
> > >ImageSource<TOutputImage>
> > >::ThreadedGenerateData(const OutputImageRegionType&,
> > >int)
> > >{
> > >itkExceptionMacro("subclass should override this method!!!");
> > >}
> > >
> > >I can remove that warning by changing the function prototype to use the
> > >noreturn
> > >attribute:
> > >
> > >virtual
> > >void ThreadedGenerateData(const OutputImageRegionType&
> > >outputRegionForThread,
> > > int threadId )
> > >__attribute__ ((noreturn));
> > >
> > >However, I believe that the noreturn attribute is not defined on all
> > >compilers.
> > >
> > >Any suggestion to get rid of that warning?
> > >
> > >Thank you.
> > >
> > >Mathieu
> > >
> > >--
> > >____________________________________________________________
> > >Mathieu Coursolle mcoursolle at rogue-research.com
> > >Rogue Researchwww.rogue-research.com
> > >Montréal, Québec, Canada
> > >
> > >_______________________________________________
> > >Insight-developers mailing list
> > >Insight-developers at itk.org
> > >http://www.itk.org/mailman/listinfo/insight-developers
> > >
> > >
> > >_______________________________________________
> > >Insight-developers mailing list
> > >Insight-developers at itk.org
> > > http://www.itk.org/mailman/listinfo/insight-developers
> > >
> > >
> > >
> > >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.itk.org/mailman/private/insight-developers/attachments/20070320/dfd2ff3f/attachment.html


More information about the Insight-developers mailing list