llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.06k stars 11.98k forks source link

Support attribute deprecated for template alias #18236

Open fdfade6f-6190-49d4-b4d3-840965bb8b0c opened 11 years ago

fdfade6f-6190-49d4-b4d3-840965bb8b0c commented 11 years ago
Bugzilla Link 17862
Version trunk
OS Linux
CC @DougGregor

Extended Description

I want to rename a templated class. To make the transition easier for the users, I'd like to keep the old class for one more version and mark it deprecated with the extensions from GCC / Clang (attribute deprecated). To avoid keeping an exact copy of the deprecated class, the use of template alias would be handy. Unfortunately Clang (3.3 and recent trunk) does not emit a warning (GCC does) for the following code in line 14:

template <class T>
struct NewClassName
{
    // ...
};

template <class T> using OldClassNameUsing __attribute__ ((deprecated))
  = NewClassName<T>;

typedef NewClassName<int> OldClassNameTypedef __attribute__ ((deprecated));

int main()
{
  OldClassNameUsing<int> objectUsing;
  OldClassNameTypedef objectTypedef;

  return 0;
}

Clang used: clang version 3.4 (194323) Target: x86_64-unknown-linux-gnu Thread model: posix

llvmbot commented 6 years ago

This has bitten us again: https://gitlab.dune-project.org/core/dune-common/merge_requests/464#note_41116

All versions of clang up to 5.0 seem to be affected according to godbolt: https://godbolt.org/g/Cpsbd7

godbolt does not support clang 6 at the moment, so I can't easily test that.

All forms of deprecating seem to be affected: [[deprecated(msg)]], attribute((deprecated(msg))), attribute((deprecated(msg)))

fdfade6f-6190-49d4-b4d3-840965bb8b0c commented 9 years ago

To state the problem more precisely, the deprecation message is only missing when templates are not specified.

template <class T>
struct NewClassName
{
    // ...
};

template <class T> using OldClassNameUsing __attribute__ ((deprecated))
  = NewClassName<T>;

using OldClassNameWithoutTemplateUsing __attribute__ ((deprecated))
  = NewClassName<int>;

typedef NewClassName<int> OldClassNameTypedef __attribute__ ((deprecated));

int main()
{
  OldClassNameUsing<int> objectUsing;  // no deprecation warning
  OldClassNameWithoutTemplateUsing objectWithoutTemplateUsing; // emits warning
  OldClassNameTypedef objectTypedef;   // emits warning

  return 0;
}
gruenich commented 2 years ago

Seems to be true for Clang 14, too.

0xBYTESHIFT commented 1 year ago

this affected me as well - https://godbolt.org/z/W9YacdGv3 (clang 16) we don't even hope that MSVC will be a reasonable compiler in the near future, but clang? just why?

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

shafik commented 1 year ago

Confirmed: https://godbolt.org/z/WfheGb8sh