GCC 6 Warnings

Clang folks,

FYI, I'm getting a lot of warnings from GCC 6.1.1 when building Clang...

Haven't had time to look closer and probably won't this week, so if
anyone would like to have a go... :slight_smile:

include/llvm/Support/Casting.h:183:72: warning: ignoring attributes on
template argument 'llvm::simplify_type<const clang::Stmt*

::SimpleType {aka const clang::Stmt*}' [-Wignored-attributes]

include/llvm/Support/Casting.h: In instantiation of 'struct
llvm::cast_retty<clang::ImplicitCastExpr, const clang::Stmt* const>':

include/llvm/Support/Casting.h:222:1: required by substitution of
'template<class X, class Y> typename std::enable_if<(!
llvm::is_simple_type<Y>::value), typename llvm::cast_retty<X, const

::ret_type>::type llvm::cast(const Y&) [with X =

clang::ImplicitCastExpr; Y = const clang::Stmt*]'

tools/clang/include/clang/AST/ASTTypeTraits.h:383:22: required from
'static const T&
clang::ast_type_traits::DynTypedNode::DynCastPtrConverter<T,

::getUnchecked(clang::ast_type_traits::ASTNodeKind, const char*)

[with T = clang::ImplicitCastExpr; BaseT = clang::Stmt]'

tools/clang/include/clang/AST/ASTTypeTraits.h:242:42: required from
'const T& clang::ast_type_traits::DynTypedNode::getUnchecked() const
[with T = clang::ImplicitCastExpr]'

tools/clang/include/clang/ASTMatchers/ASTMatchersInternal.h:283:19:
required from 'bool
clang::ast_matchers::internal::MatcherInterface<T>::dynMatches(const
clang::ast_type_traits::DynTypedNode&,
clang::ast_matchers::internal::ASTMatchFinder*,
clang::ast_matchers::internal::BoundNodesTreeBuilder*) const [with T =
clang::ImplicitCastExpr]'

tools/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp:1957:1:
  required from here

include/llvm/Support/Casting.h:134:74: warning: ignoring attributes on
template argument 'llvm::simplify_type<const clang::Stmt*

::SimpleType {aka const clang::Stmt*}' [-Wignored-attributes]

   return isa_impl_wrap<X, const Y,

Clang folks,

FYI, I'm getting a lot of warnings from GCC 6.1.1 when building Clang...

Haven't had time to look closer and probably won't this week, so if
anyone would like to have a go... :slight_smile:

include/llvm/Support/Casting.h:183:72: warning: ignoring attributes on
template argument 'llvm::simplify_type<const clang::Stmt*
>::SimpleType {aka const clang::Stmt*}' [-Wignored-attributes]

GCC seems confused. There are no attributes here. Perhaps it's confused
because clang::Stmt itself has an alignment attribute on its definition?

include/llvm/Support/Casting.h: In instantiation of 'struct

Maybe GCC sees a declaration of clang::Stmt without the attribute before it sees the definition? I know GCC is a lot more picky about the order in which it sees attributes.

I think this could be related:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71463

HTH

Hum, it does look like the same problem.

Eric, one of the comments was:

"The attribute isn't properly part of the C++ type, so in the testcase
below A<fna> needs to be the same type as A<fn>, and so they share a
member function. So we have to choose which type to use as the
canonical type, and we choose the type without the attribute. And
that's what the "ignoring attributes" warning is telling you.

typedef int fn();
typedef int fna() __attribute ((warn_unused_result));"

Do we use the Casting classes with Stmt (which has alignment
attribute) as well as with other classes that don't have any
attributes?

Anyway, this seems like a silly warning in templates, as you're
expected to use it with multiple types and they can have different
attributes anyway.

How is c++17 attributes going to work in this case? I assume they're
going to be different types (in decltype's eyes), so GCC could do a
similar implementation.

cheers,
--renato

> I think this could be related:
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71463

Hum, it does look like the same problem.

I don't think so. The difference is, in that case, there is an attribute on
the entity that's part of the sugared type and gets erased through the
template argument. In this case, there is not.

I don't have GCC 6.1.1 so I can't put together a reduced testcase, but as
far as I can see, it would be something like this:

struct alignas(8) S {};
template<typename T> struct id { typedef T type; };
template<typename T> struct X {};
X<id<const S*>::type> x;

Note that the error GCC gives is for the template argument to X, not the
template argument to id, so somehow passing 'const S*' through a template
parameter and a typedef has made GCC incorrectly decide that there's an
attribute on the sugared type.

Eric, one of the comments was: