views:

1793

answers:

4

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.

+7  A: 

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.

Darian Miller
+8  A: 

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:

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

You might also find this tutorial helpful. However it's in German.

Ulrich Gerhardt
This tutorial lists all the warning and hint identifiers in Delphi 2007 (not 2009), with detailed explanations in German.
Jan Goyvaerts
Oops - I somehow read over that 2009/Unicode string stuff. :-)
Ulrich Gerhardt
+5  A: 

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
Jan Goyvaerts

related questions