Skip to content

Commit 1719e4e

Browse files
committed
Warn if both file and configuration are different
1 parent cee78ce commit 1719e4e

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3719,7 +3719,7 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo &ctu, const std::list<C
37193719
}
37203720
if (it->second.hash == nameLoc.hash)
37213721
continue;
3722-
if (it->second.configuration != nameLoc.configuration)
3722+
if (it->second.fileName == nameLoc.fileName && it->second.configuration != nameLoc.configuration)
37233723
continue;
37243724
// Same location, sometimes the hash is different wrongly (possibly because of different token simplifications).
37253725
if (it->second.isSameLocation(nameLoc))

test/cli/whole-program/odr4.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifdef X
2+
struct S {};
3+
#endif

test/cli/whole-program/odr5.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
struct S {};

test/cli/whole-program_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,24 @@ def test_checkclass_project_builddir_j(tmpdir):
337337
os.mkdir(build_dir)
338338
__test_checkclass_project(tmpdir, ['-j2', '--cppcheck-build-dir={}'.format(build_dir)])
339339

340+
def test_ctu_odr_config():
341+
args = [
342+
'-q',
343+
'--template=simple',
344+
'--enable=information,style',
345+
'--error-exitcode=1',
346+
'whole-program/odr4.cpp',
347+
'whole-program/odr5.cpp'
348+
]
349+
350+
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
351+
lines = stderr.splitlines()
352+
assert lines == [
353+
"whole-program{}odr4.cpp:6:1: error: The one definition rule is violated, different classes/structs have the same name 'S' [ctuOneDefinitionRuleViolation]".format(os.path.sep)
354+
]
355+
assert stdout == ''
356+
assert ret == 1, stdout
357+
340358

341359
def __test_nullpointer_file0(extra_args):
342360
args = [

0 commit comments

Comments
 (0)