[cmake-developers] conditionals in generator expressions

Brad King brad.king at kitware.com
Mon Sep 17 09:41:30 EDT 2012


On 09/17/2012 08:50 AM, Stephen Kelly wrote:
> I've fixed all errors and warnings that can be fixed. Some remain due to 
> compiler bugs which claim some code in a template is unreachable (but that's 
> only due to the template parameters).

The HP warnings are not a compiler bug.  It looks like other compilers
picked up on it too but you suppressed the warnings in the topic.
In this code:

  template<bool linker, bool soname, bool dirQual, bool nameQual>
  ...
  // TODO: static_assert(!(name && dir))
  if(nameQual)
    {
    return cmSystemTools::GetFilenameName(result);
    }
  else if (dirQual)
    {
    return cmSystemTools::GetFilenamePath(result);
    }
  return result;

when either nameQual or dirQual is true that is a compile-time constant
so the "return result" line is truly unreachable in that instantiation.
You need to use compile-time conditional code rather than "runtime"
tests of compile-time constants.  This is true for the other template
parameters too.

> I think it would make sense to rewrite the branch to squash the whitespace 
> fixes before merging to master though.

Yes, I can do this when the topic is done.

-Brad



More information about the cmake-developers mailing list