Identifiers for Delphi's $WARN compiler directive

Delphi has a $WARN compiler directive that allows one to selectively enable or disable specific warnings. The Delphi 2009 help file describes the syntax:

{$WARN identifier ON|OFF}

But it only lists the identifiers for 6 warnings.

I'd like to have a complete list of all the warning identifiers. In particular, I want to know the identifiers for the implicit string cast warnings W1057 and W1058 in Delphi 2009.

I managed to guess the one for implicit Ansi->Unicode casts (W1057):

{$WARN IMPLICIT_STRING_CAST OFF}

Googling for that found me the other one:

{$WARN IMPLICIT_STRING_CAST_LOSS OFF}

Though that solves my immediate need, I'd still like to know the complete list of warning identifiers. Stuff like this should be documented.


Darian's right that the DCCStrs.pas lists the identifiers used by the Delphi compiler. It hadn't occurred to me to search the source, since Delphi doesn't include the source to its compiler.

I've extracted the identifiers for hints and warnings from that file:

  • {$WARN ASG_TO_TYPED_CONST OFF}
  • {$WARN BAD_GLOBAL_SYMBOL OFF}
  • {$WARN BOUNDS_ERROR OFF}
  • {$WARN CASE_LABEL_RANGE OFF}
  • {$WARN COMBINING_SIGNED_UNSIGNED OFF}
  • {$WARN COMPARING_SIGNED_UNSIGNED OFF}
  • {$WARN COMPARISON_FALSE OFF}
  • {$WARN COMPARISON_TRUE OFF}
  • {$WARN CONSTRUCTING_ABSTRACT OFF}
  • {$WARN CVT_ACHAR_TO_WCHAR OFF}
  • {$WARN CVT_NARROWING_STRING_LOST OFF}
  • {$WARN CVT_WCHAR_TO_ACHAR OFF}
  • {$WARN CVT_WIDENING_STRING_LOST OFF}
  • {$WARN DUPLICATE_CTOR_DTOR OFF}
  • {$WARN DUPLICATES_IGNORED OFF}
  • {$WARN EXPLICIT_STRING_CAST OFF}
  • {$WARN EXPLICIT_STRING_CAST_LOSS OFF}
  • {$WARN FILE_OPEN OFF}
  • {$WARN FILE_OPEN_UNITSRC OFF}
  • {$WARN FOR_LOOP_VAR_UNDEF OFF}
  • {$WARN FOR_LOOP_VAR_VARPAR OFF}
  • {$WARN FOR_VARIABLE OFF}
  • {$WARN GARBAGE OFF}
  • {$WARN HIDDEN_VIRTUAL OFF}
  • {$WARN HIDING_MEMBER OFF}
  • {$WARN HPPEMIT_IGNORED OFF}
  • {$WARN HRESULT_COMPAT OFF}
  • {$WARN IMAGEBASE_MULTIPLE OFF}
  • {$WARN IMPLICIT_IMPORT OFF}
  • {$WARN IMPLICIT_STRING_CAST OFF}
  • {$WARN IMPLICIT_STRING_CAST_LOSS OFF}
  • {$WARN IMPLICIT_VARIANTS OFF}
  • {$WARN INVALID_DIRECTIVE OFF}
  • {$WARN LOCAL_PINVOKE OFF}
  • {$WARN LOCALE_TO_UNICODE OFF}
  • {$WARN MESSAGE_DIRECTIVE OFF}
  • {$WARN NO_CFG_FILE_FOUND OFF}
  • {$WARN NO_RETVAL OFF}
  • {$WARN OPTION_TRUNCATED OFF}
  • {$WARN PACKAGE_NO_LINK OFF}
  • {$WARN PACKAGED_THREADVAR OFF}
  • {$WARN PRIVATE_PROPACCESSOR OFF}
  • {$WARN RLINK_WARNING OFF}
  • {$WARN STRING_CONST_TRUNCED OFF}
  • {$WARN SUSPICIOUS_TYPECAST OFF}
  • {$WARN SYMBOL_DEPRECATED OFF}
  • {$WARN SYMBOL_EXPERIMENTAL OFF}
  • {$WARN SYMBOL_LIBRARY OFF}
  • {$WARN SYMBOL_PLATFORM OFF}
  • {$WARN TYPED_CONST_VARPAR OFF}
  • {$WARN TYPEINFO_IMPLICITLY_ADDED OFF}
  • {$WARN UNICODE_TO_LOCALE OFF}
  • {$WARN UNIT_DEPRECATED OFF}
  • {$WARN UNIT_EXPERIMENTAL OFF}
  • {$WARN UNIT_INIT_SEQ OFF}
  • {$WARN UNIT_LIBRARY OFF}
  • {$WARN UNIT_NAME_MISMATCH OFF}
  • {$WARN UNIT_PLATFORM OFF}
  • {$WARN UNSAFE_CAST OFF}
  • {$WARN UNSAFE_CODE OFF}
  • {$WARN UNSAFE_TYPE OFF}
  • {$WARN UNSUPPORTED_CONSTRUCT OFF}
  • {$WARN USE_BEFORE_DEF OFF}
  • {$WARN WIDECHAR_REDUCED OFF}
  • {$WARN XML_CREF_NO_RESOLVE OFF}
  • {$WARN XML_EXPECTED_CHARACTER OFF}
  • {$WARN XML_INVALID_NAME OFF}
  • {$WARN XML_INVALID_NAME_START OFF}
  • {$WARN XML_NO_MATCHING_PARM OFF}
  • {$WARN XML_NO_PARM OFF}
  • {$WARN XML_UNKNOWN_ENTITY OFF}
  • {$WARN XML_WHITESPACE_NOT_ALLOWED OFF}
  • {$WARN ZERO_NIL_COMPAT OFF}

I looked through the help and didn't see a full list...so poking around the code it appears the compiler warning constants are all listed in: CodeGear\RAD Studio\6.0\sources\toolsapi\DCCStrs.pas

Search for "Implicit_String_Cast_Loss" and you'll see the constant sIMPLICIT_STRING_CAST_LOSS = 'DCC_IMPLICIT_STRING_CAST_LOSS';

I would assume the rest of the DCC_xxx strings with corresponding X_true/_false/_error defines are what you are after.

Online help hasn't been very good since Delphi 7.


Something else not mentioned in the Delphi 2009 documentation:

The $WARN directive now has a 3rd option ERROR in addition to ON and OFF. So you can have:

{$WARN IMPLICIT_STRING_CAST OFF} to disable the warning
{$WARN IMPLICIT_STRING_CAST ON} to enable warning
{$WARN IMPLICIT_STRING_CAST ERROR} to turn the warning into an error