From 5781ffcecdf20d2bea57c7b34c723e4e5aa04c46 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Wed, 10 Jun 2026 19:08:18 +0200 Subject: [PATCH 1/2] Fix #14180 FN intToPointerCast with binary integer literal --- lib/checkother.cpp | 2 ++ test/testother.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index b5fd0dda361..801dc529568 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -464,6 +464,8 @@ void CheckOtherImpl::warningIntToPointerCast() format = "decimal"; else if (MathLib::isOct(from->str())) format = "octal"; + else if (MathLib::isBin(from->str())) + format = "binary"; else continue; intToPointerCastError(tok, format); diff --git a/test/testother.cpp b/test/testother.cpp index 93e67229f43..710312de575 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2362,6 +2362,9 @@ class TestOther : public TestFixture { checkIntToPointerCast("struct S { int i; };\n" // #13886, don't crash "int f() { return sizeof(((struct S*)0)->i); }"); ASSERT_EQUALS("", errout_str()); + + checkIntToPointerCast("auto p = (int*)0b10;"); // #14180 + ASSERT_EQUALS("[test.cpp:1:10]: (portability) Casting non-zero binary integer literal to pointer. [intToPointerCast]\n", errout_str()); } struct CheckInvalidPointerCastOptions @@ -4864,6 +4867,33 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:1:20]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + check("struct S {\n" // #14817 + " explicit S(int *a) : m{ a[0], a[1] } {}\n" + " int m[2];\n" + "};" + "struct T {\n" + " explicit T(int *a) : m{ &a[0], &a[1] } {}\n" + " int* m[2];\n" + "};\n" + "struct X{ int& r1, &r2; }\n" + "int f(int* a) {\n" + " S m[2]{a[0], a[1]};\n" + " return m[0].r1 + m[1].r2;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2:21]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\n", + errout_str()); + + check("class A {\n" // #11471 + "public:\n" + " A(const int& i, int) : m_i(&i) {}\n" + " const int* m_i;\n" + "};\n" + "A f(int& s) {\n" + " return A(s, 0);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:6:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\n", + errout_str()); } void constArray() { From 6c67588ede1bb3b6b715580e79719e6c57276a14 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Wed, 10 Jun 2026 19:10:24 +0200 Subject: [PATCH 2/2] Undo --- test/testother.cpp | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/test/testother.cpp b/test/testother.cpp index 710312de575..73f10cbe76e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4867,33 +4867,6 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" "[test.cpp:1:20]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n", errout_str()); - - check("struct S {\n" // #14817 - " explicit S(int *a) : m{ a[0], a[1] } {}\n" - " int m[2];\n" - "};" - "struct T {\n" - " explicit T(int *a) : m{ &a[0], &a[1] } {}\n" - " int* m[2];\n" - "};\n" - "struct X{ int& r1, &r2; }\n" - "int f(int* a) {\n" - " S m[2]{a[0], a[1]};\n" - " return m[0].r1 + m[1].r2;\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:2:21]: (style) Parameter 'a' can be declared as pointer to const [constParameterPointer]\n", - errout_str()); - - check("class A {\n" // #11471 - "public:\n" - " A(const int& i, int) : m_i(&i) {}\n" - " const int* m_i;\n" - "};\n" - "A f(int& s) {\n" - " return A(s, 0);\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:6:10]: (style) Parameter 's' can be declared as reference to const [constParameterReference]\n", - errout_str()); } void constArray() {