GeneralPurpose-LinkerWarnings¶
Fix all linker warnings and errors
Required inputs: IR
Bad code (ODR violation):
// point.hpp
struct Point { // ERROR: ODR violation for struct Point; extra/missing field "Foo::z"
int x;
int y;
#ifdef ENABLE_3D
int z;
#endif // ENABLE_3D
};
// math2d.cpp
#include "point.hpp"
int dot_product(Point a, Point b) {
return (a.x * b.x) + (a.y * b.y);
}
// math3d.cpp
#define ENABLE_3D
#include "point.hpp"
Point cross_product(Point a, Point b) {
return Point{
(a.y * b.z) - (a.z * b.y),
(a.z * b.x) - (a.x * b.z),
(a.x * b.y) - (a.y * b.x)
};
}
Bad code (mismatched ellipsis parameter):
// foo.c void f(int x, ...); // ERROR: Parameter "..." does not match type "int" // bar.c void f(int x, int y); // // ERROR: warning: Parameter type "int" does not match "..."
Good code (separate types; no ODR violation):
// point.hpp
struct Point2d {
int x;
int y;
};
struct Point3d {
int x;
int y;
int z;
};
// math2d.cpp
#include "point.hpp"
int dot_product(Point2d a, Point2d b) {
// ...
}
// math3d.cpp
#include "point.hpp"
Point3d cross_product(Point3d a, Point3d b) {
// ...
}
Good code (matching parameters):
// func.h void func(int x, ...); // OK: matching declaration in all translation units // foo.c #include "func.h" // bar.c #include "func.h"
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
cafe_not_compatible_with_previous_decl |
{} |
None |
False |
differing_typedef_redefinition |
Typedef redefined with different definition. |
None |
False |
ellipsis_mismatch |
Parameter {kind1} does not match {kind2} at {pos} |
None |
False |
except_spec_mismatch |
{kind1} does not match {kind2} at {pos} |
None |
False |
extra_field |
ODR violation for {defn}; {kind} field {field} at {field_pos} compared to definition at {pos} |
None |
False |
implicit_ellipsis_mismatch |
Missing parameters should not match an ellipsis parameter at {pos} |
None |
False |
implicit_ellipsis_mismatch_rev |
An ellipsis parameter should not match missing parameters at {pos} |
None |
False |
implicit_length_match |
No parameters implicitly match {num} parameter{p} in {decl} at {pos} |
None |
False |
implicit_length_match_rev |
{num} parameter{p} implicitly match{es} no parameters in {decl} at {pos} |
None |
False |
implicit_promotion_mismatch |
Missing parameters do not match an unpromoted parameter type {type} at {pos} |
None |
False |
implicit_promotion_mismatch_rev |
An unpromoted parameter type {type} does not match missing parameters at {pos} |
None |
False |
incompatible_enumerator_names |
ODR violation in redefinition at {pos}; enumerators {enums1} do not match {enums2} |
None |
False |
incompatible_enumerator_value |
ODR violation in redefinition at {pos}; enumerator value {val1} does not match {val2} |
None |
False |
incompatible_field_name |
ODR violation for {defn} compared to definition at {pos}; field {field} at {pos1} does not match field name {field2} at {pos2}{check} |
None |
False |
incompatible_field_type |
ODR violation for {defn} compared to definition at {pos}; field {field} has incompatible type {type1} at {pos1} compared to type {type2} at {pos2}{check} |
None |
False |
length_mismatch |
{num1} parameter{p1} {versus} {num2} parameter{p2} at {pos} |
None |
False |
linkage_mismatch |
{kind1} does not match {kind2} at {pos} |
None |
False |
parameter_type_mismatch |
{kind} type {type1} {versus} {type2} at {pos}{implicit2}{remark} |
None |
False |
return_type_mismatch |
{kind} type {type1} {versus} {type2} at {pos}{implicit2}{remark} |
None |
False |
variable_type_mismatch |
{kind} type {type1} {versus} {type2} at {pos}{implicit2}{remark} |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
check_exception_specification¶
check_exception_specification : bool = False
check_linkage_declaration¶
check_linkage_declaration : bool = False
reported_messages¶
reported_messages
If provided, only the listed message types are reported. If set to None, all message types are reported.Type: set[LinkerMessage] | None
Default:
{'Adding_Library', 'Basepath_Mismatch', 'Cannot_Open_Error', 'Cannot_Open_Ignored', 'Cannot_Open_Warning', 'Class_Struct_Mismatch', 'Compiler_Mismatch', 'Cylic_PCH', 'Different_Symbols', 'Empty_Linker_Result', 'Field_Offset_Mismatch', 'General_Field_Remark', 'General_Field_Warning', 'General_ODR_Violation', 'Implicit_Func_Decl_Return_Type_Mismatch', 'Missing_Main', 'Missing_PCH_Error', 'Missing_PCH_Warning', 'Multiple_Definition', 'Multiple_Main', 'No_IR_File', 'Old_IR_File_Error', 'Old_IR_File_Warning', 'PCH_Without_Clients', 'Reference_To_Library', 'Runtimelib_Archive', 'Runtimelib_PCH', 'Template_Specialization_Vs_Instance', 'Tolerated_Type_Difference', 'Type_Alignment_Mismatch', 'Type_Size_Mismatch', 'Unresolved_Declaration', 'Unused_Archive_Member', 'Unused_Library', 'User_System_Include_Mismatch'}
reported_severities¶
reported_severities
List of severities to display.Type: set[LinkerSeverity]
Default:
{'error', 'warning'}
use_rule_severity¶
use_rule_severity : bool = False
Option Types¶
These types are used by options listed above:
LinkerMessage¶
An enumeration.Adding_Library
Reference_To_Library
Cannot_Open_Error
Cannot_Open_Warning
Cannot_Open_Ignored
No_IR_File
Old_IR_File_Error
Old_IR_File_Warning
Cylic_PCH
Runtimelib_PCH
Runtimelib_Archive
Missing_PCH_Error
Missing_PCH_Warning
PCH_Without_Clients
Basepath_Mismatch
Compiler_Mismatch
General_ODR_Violation
ODR_Violation_In_Fields
ODR_Violation_In_Field_Types
Tolerated_Type_Difference
ODR_Violation_In_Enumerators
Implicit_Func_Decl_Return_Type_Mismatch
Type_Size_Mismatch
Type_Alignment_Mismatch
Field_Offset_Mismatch
Multiple_Definition
Unresolved_Declaration
General_Field_Remark
General_Field_Warning
Missing_Main
Multiple_Main
Template_Specialization_Vs_Instance
Class_Struct_Mismatch
Unused_Archive_Member
Unused_Library
Empty_Linker_Result
User_System_Include_Mismatch
Different_Symbols
LinkerSeverity¶
An enumeration.disabled
progress
remark
warning
error