Show: Object Pascal C++
Display Preferences

Errors and Warnings of Clang-enhanced C++ Compilers

From Appmethod Topics
Jump to: navigation, search

Go Up to Clang-enhanced C++ Compilers


Controlling Warning Messages

The option Enable all warnings (on Project > Options > C++ Compiler > Warnings) invokes the compiler with the -Weverything option, which is a superset of -Wall (for all "easy to avoid" constructions).

Warnings may be enabled or suppressed individually, which requires the name of the warning. To show these names, pass -fdiagnostics-show-option to the compiler. Doing so changes a warning like this:

File1.cpp:32:11: warning: unused variable 'foo'

to this:

File1.cpp:32:11: warning: unused variable 'foo' [-Wunused-variable]

You can then use -Wunused-variable to turn on that warning specifically, without enabling others. To disable that warning, replace the leading -W with -Wno-, and use it in combination with an option to enable the desired warning level. For example: -Wall -Wno-unused-variable will enable all easy to avoid warnings except for unused variables.

Common Errors Porting from BCC32

Code ported from BCC32 may exhibit some of these errors (listed alphabetically, ignoring placeholders like 'x').

'x' does not refer to a value (in template)

Type names that are dependent on the template parameter must be preceded by typename. Without it, for example:

template <class T>
void doSomething() {
  T::member *var;
}

a * intended for pointer declaration will actually be interpreted as multiplication; and if the intended variable already happens to be in scope, this error will occur, trying to multiply a type name ('member' in this example), which is not a value.

Missing 'typename' prior to dependent type name 'x'

Type names that are dependent on the template parameter must be preceded by typename. When omitted, some edge cases may generate other errors, but in general the error and solution is clear.

Pasting formed 'x', an invalid preprocessing token

Token pasting with the preprocessor's ## operator must form a single valid token. In many cases, the operator is not necessary in the first place, so simply removing it resolves the issue.

Public symbol 'x' defined in both module A and B

For example:

[ilink64 Error] Error: Public symbol 'triplet::sum' defined in both module C:\USERS\WIN764\NODES.O and C:\USERS\WIN764\UNIT1.O

Static data members should be declared in a header, and defined only once in a source file (not the header).

ILINK64 is documented here: ILINK64.EXE, the 64-bit Incremental Linker.

Use of undeclared identifier 'x' (in template)

Due to two-phase name lookup in templates, identifiers found in base classes are not resolved unless qualified with this->

Also, type names that are dependent on the template parameter must be preceded by typename. Without it, for example:

template <class T>
void doSomething() {
  T::member *var;
}

a * intended for pointer declaration will actually be interpreted as multiplication; and unless the intended variable already happens to be in scope, this error will occur, trying to multiply the template-value with the undeclared identifier ('var' in this example).

Common Warnings Porting from BCC32

Code ported from BCC32 may exhibit some of these warnings (listed alphabetically), which may be suppressed.

Conversion from string literal to 'char *' is deprecated

-Wdeprecated-writable-strings

Assigning a plain char pointer to a literal C-string is discouraged. Make the pointer const (and if appropriate, consider using std::string).

Implicit conversion changes signedness

-Wsign-conversion

BCC32 ignores an assignment from signed to unsigned. Clang-enhanced C++ compilers do notice such assignments, and emit a warning or error message.

See Also

Personal tools
In other languages