Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  TestIntToEnumCast.cpp

  Sprache: C
 

enum UnscopedEnum { kFirst, kSecond, kThird };

enum class ScopedEnum { A, B, C };

enum class TypedEnum : unsigned { X = 0, Y = 1 };

// Minimal mock of the IPC base class.
namespace mozilla {
namespace ipc {
class IProtocol {
public:
  virtual ~IProtocol() = default;
};
// namespace ipc
// namespace mozilla

// Simulates an IPC actor class (inherits from IProtocol).
class MockCDMParent : public mozilla::ipc::IProtocol {
public:
  void RecvDecryptFailed(unsigned aStatus) {
    ScopedEnum e = static_cast<ScopedEnum>(aStatus); // expected-error {{static_cast from builtin type 'unsigned int' to enum type 'ScopedEnum' in an IPC actor method}} expected-note {{consider using the enum type directly}}
  }

  void RecvOnRejectPromise(unsigned aException) {
    UnscopedEnum e = static_cast<UnscopedEnum>(aException); // expected-error {{static_cast from builtin type 'unsigned int' to enum type 'UnscopedEnum' in an IPC actor method}} expected-note {{consider using the enum type directly}}
  }

  void RecvDecoderInit(unsigned aStatus) {
    TypedEnum e = static_cast<TypedEnum>(aStatus); // expected-error {{static_cast from builtin type 'unsigned int' to enum type 'TypedEnum' in an IPC actor method}} expected-note {{consider using the enum type directly}}
  }

  void RecvCStyleCast(unsigned aStatus) {
    ScopedEnum e = (ScopedEnum)aStatus; // expected-error {{C-style cast from builtin type 'unsigned int' to enum type 'ScopedEnum' in an IPC actor method}} expected-note {{consider using the enum type directly}}
  }

  void RecvFunctionalCast(unsigned aStatus) {
    UnscopedEnum e = UnscopedEnum(aStatus); // expected-error {{functional cast from builtin type 'unsigned int' to enum type 'UnscopedEnum' in an IPC actor method}} expected-note {{consider using the enum type directly}}
  }

  // Casts inside a lambda body (e.g. a promise callback) must also be caught.
  void RecvInLambda(unsigned aStatus) {
    auto callback = [](unsigned aValue) {
      ScopedEnum e = static_cast<ScopedEnum>(aValue); // expected-error {{static_cast from builtin type 'unsigned int' to enum type 'ScopedEnum' in an IPC actor method}} expected-note {{consider using the enum type directly}}
      return e;
    };
    callback(aStatus);
  }

};

// Simulates a non-IPC class — no warnings expected.
class RegularClass {
public:
  void doSomething(unsigned aValue) {
    ScopedEnum e1 = static_cast<ScopedEnum>(aValue);
    ScopedEnum e2 = (ScopedEnum)aValue;
    UnscopedEnum e3 = UnscopedEnum(aValue);
  }
};

// Free function — no warnings expected.
void freeFunction(unsigned aValue) {
  ScopedEnum e1 = static_cast<ScopedEnum>(aValue);
  ScopedEnum e2 = (ScopedEnum)aValue;
  UnscopedEnum e3 = UnscopedEnum(aValue);
}

Messung V0.5 in Prozent
C=89 H=96 G=92

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002