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

            Bug ID: 102439
           Summary: deprecated attributes do not work on struct/class if
                    type is auto deduced
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: spaun2002 at protonmail dot com
  Target Milestone: ---

The following code compiles with no warnings/errors by all gcc versions that
support std=c++14.
The same code does not compile by clang or msvc compilers (the latter was run
with /W4 /WX arguments and without __attribute__ part).

If I uncomment type_v1 const a = type_v1{10}; then gcc properly fails to
compile.

Expected behavior: gcc emits warning on `auto a = type_v1{10}` line.

// gcc -Wall --pedantic -std=c++14 -Wattributes -Wdeprecated-declarations
-Werror

#include <iostream>

struct [[deprecated]] type_v1 {
  int a;
} __attribute__ ((__deprecated__));

int main() {
  auto a = type_v1{10};       // this one should not compile
  //type_v1 a = type_v1{10};  // rightfully fails to compile
  std::cout << a.a << std::endl;
  return 0;
}

Reply via email to