[llvm-bugs] [Bug 32736] New: clang-cl never diagnoses use of forward-declared enums

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 21 12:47:10 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=32736

            Bug ID: 32736
           Summary: clang-cl never diagnoses use of forward-declared enums
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Driver
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nicolasweber at gmx.de
                CC: llvm-bugs at lists.llvm.org

This errors out with clang and gcc as it should:

$ cat test.cc
enum E; void f(E);
enum E {kA}; void f(E a) { if (a == kA) {}}


However, clang-cl always accepts it without a warning. This bit in SemaDecl.cpp
tries to emit ext_ms_forward_ref_enum for this:

    // If this is an undefined enum, warn.
    if (TUK != TUK_Definition && !Invalid) {
      TagDecl *Def;
      if ((getLangOpts().CPlusPlus11 || getLangOpts().ObjC2) &&
          cast<EnumDecl>(New)->isFixed()) {
        // C++0x: 7.2p2: opaque-enum-declaration.
        // Conflicts are diagnosed above. Do nothing.
      }
      else if (PrevDecl && (Def = cast<EnumDecl>(PrevDecl)->getDefinition())) {
        Diag(Loc, diag::ext_forward_ref_enum_def)
          << New;
        Diag(Def->getLocation(), diag::note_previous_definition);
      } else {
        unsigned DiagID = diag::ext_forward_ref_enum;
        if (getLangOpts().MSVCCompat)
          DiagID = diag::ext_ms_forward_ref_enum;
        else if (getLangOpts().CPlusPlus)
          DiagID = diag::err_forward_ref_enum;
        Diag(Loc, DiagID);


But:

1. ext_ms_forward_ref_enum is an Extension<> and clang-cl doesn't expose
-pedantic (it probably should be an ExtWarn<>)

2. Worse, isFixed() in the if above is true, so the lower else is never entered
in Microsoft mode.

That's due to this, also in SemaDecl.cpp:

      if (getLangOpts().MSVCCompat || TUK == TUK_Definition) {
        // Microsoft enums are always of int type.
        EnumUnderlying = Context.IntTy.getTypePtr();
        EnumUnderlyingIsImplicit = true;
      }

This causes the EnumDecl to believe that it's IsFixed.

Last touched by majnemer in 249667, added by fpichet in 116704.


Probably need to pipe EnumUnderlyingIsImplicit to the diag block and diag if
that's set?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170421/2c850d39/attachment.html>


More information about the llvm-bugs mailing list