Bug 364092

Summary: User literals can break QString related checks
Product: [Developer tools] clazy Reporter: Mathias Hasselmann <mathias.hasselmann>
Component: generalAssignee: Sergio Martins <smartins>
Status: RESOLVED FIXED    
Severity: normal CC: smartins
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Mathias Hasselmann 2016-06-08 09:30:30 UTC
C++ 11 user literals like

    inline constexpr QLatin1String operator"" _L1 (const char *str, std::size_t len)
    {
        return QLatin1String(str, len);
    }

seem to blind QString related checks like qlatin1string-allocations.
Comment 1 Sergio Martins 2016-06-09 19:00:08 UTC
Git commit 1b6045fe068acd7422dc5ede2e1cd62b609878e2 by Sergio Martins.
Committed on 09/06/2016 at 18:59.
Pushed by smartins into branch 'master'.

qstring-allocations: Add unit-test for bug 364092

M  +11   -0    tests/qstring-allocations/main.cpp
M  +11   -0    tests/qstring-allocations/main.cpp_fixed.cpp.expected

http://commits.kde.org/clazy/1b6045fe068acd7422dc5ede2e1cd62b609878e2
Comment 2 Sergio Martins 2016-06-09 19:15:01 UTC
AST for the test-case

`-FunctionDecl 0x38e3e28 <line:9:1, line:12:1> line:9:6 test364092 'void (void)'
  `-CompoundStmt 0x38e41d0 <line:10:1, line:12:1>
    `-DeclStmt 0x38e41b8 <line:11:5, col:23>
      `-VarDecl 0x38e3ee0 <col:5, col:17> col:13 s 'class QString' cinit
        `-ExprWithCleanups 0x38e41a0 <col:13, col:17> 'class QString'
          `-CXXConstructExpr 0x38e4168 <col:13, col:17> 'class QString' 'void (class QString &&) noexcept' elidable
            `-MaterializeTemporaryExpr 0x38e4150 <col:17> 'class QString' xvalue
              `-CXXBindTemporaryExpr 0x38e4130 <col:17> 'class QString' (CXXTemporary 0x38e4128)
                `-ImplicitCastExpr 0x38e4110 <col:17> 'class QString' <ConstructorConversion>
                  `-CXXConstructExpr 0x38e40d8 <col:17> 'class QString' 'void (class QLatin1String)'
                    `-CXXConstructExpr 0x38e40a0 <col:17> 'class QLatin1String' 'void (class QLatin1String &&) noexcept' elidable
                      `-MaterializeTemporaryExpr 0x38e4088 <col:17> 'class QLatin1String' xvalue
                        `-UserDefinedLiteral 0x38e4048 <col:17> 'class QLatin1String'
                          |-ImplicitCastExpr 0x38e4018 <col:20> 'class QLatin1String (*)(const char *, std::size_t)' <FunctionToPointerDecay>
                          | `-DeclRefExpr 0x38e3f90 <col:20> 'class QLatin1String (const char *, std::size_t)' lvalue Function 0x38e3980 'operator""_L1' 'class QLatin1String (const char *, std::size_t)'
                          |-ImplicitCastExpr 0x38e4030 <col:17> 'const char *' <ArrayToPointerDecay>
                          | `-StringLiteral 0x38e3f40 <col:17> 'const char [2]' lvalue "F"
                          `-IntegerLiteral 0x38e3f70 <col:17> 'unsigned long' 1
Comment 3 Sergio Martins 2016-06-09 19:35:22 UTC
AST with QLatin1String directly:

`-FunctionDecl 0x3de6c98 <line:9:1, line:12:1> line:9:6 test364092 'void (void)'
  `-CompoundStmt 0x3de6fb0 <line:10:1, line:12:1>
    `-DeclStmt 0x3de6f98 <line:11:5, col:35>
      `-VarDecl 0x3de6d50 <col:5, col:34> col:13 s 'class QString' cinit
        `-ExprWithCleanups 0x3de6f80 <col:13, col:34> 'class QString'
          `-CXXConstructExpr 0x3de6f48 <col:13, col:34> 'class QString' 'void (class QString &&) noexcept' elidable
            `-MaterializeTemporaryExpr 0x3de6f30 <col:17, col:34> 'class QString' xvalue
              `-CXXBindTemporaryExpr 0x3de6f10 <col:17, col:34> 'class QString' (CXXTemporary 0x3de6f08)
                `-ImplicitCastExpr 0x3de6ef0 <col:17, col:34> 'class QString' <ConstructorConversion>
                  `-CXXConstructExpr 0x3de6eb8 <col:17, col:34> 'class QString' 'void (class QLatin1String)'
                    `-CXXConstructExpr 0x3de6e80 <col:17, col:34> 'class QLatin1String' 'void (class QLatin1String &&) noexcept' elidable
                      `-MaterializeTemporaryExpr 0x3de6e68 <col:17, col:34> 'class QLatin1String' xvalue
                        `-CXXFunctionalCastExpr 0x3de6e40 <col:17, col:34> 'class QLatin1String' functional cast to class QLatin1String <ConstructorConversion>
                          `-CXXConstructExpr 0x3de6e08 <col:17, col:34> 'class QLatin1String' 'void (const char *) noexcept'
                            `-ImplicitCastExpr 0x3de6df0 <col:31> 'const char *' <ArrayToPointerDecay>
                              `-StringLiteral 0x3de6dc0 <col:31> 'const char [2]' lvalue "F"
Comment 4 Sergio Martins 2016-06-10 10:58:02 UTC
Git commit ae04679732a20fc406f8d2e355af7fefde00e7f7 by Sergio Martins.
Committed on 10/06/2016 at 10:57.
Pushed by smartins into branch 'master'.

qstring-allocations: Don't be blinded by user defined literals

Now also warns for user defined literals returning QLatin1String

M  +5    -1    checks/level2/qstring-allocations.cpp
M  +5    -0    checks/level2/qstring-allocations.h
M  +1    -1    tests/qstring-allocations/main.cpp
M  +1    -0    tests/qstring-allocations/main.cpp.expected
M  +1    -1    tests/qstring-allocations/main.cpp_fixed.cpp.expected

http://commits.kde.org/clazy/ae04679732a20fc406f8d2e355af7fefde00e7f7
Comment 5 Sergio Martins 2016-06-10 10:58:03 UTC
Git commit 7ace8c7a9f4e53efbce017fd95d33797b426bace by Sergio Martins.
Committed on 10/06/2016 at 00:11.
Pushed by smartins into branch 'master'.

qstring-allocations: Also warn for QL1S with two arguments

Doesn't fix 364092, but it's a step forward

M  +20   -10   checks/level2/qstring-allocations.cpp
M  +5    -0    tests/qstring-allocations/main.cpp
M  +1    -0    tests/qstring-allocations/main.cpp.expected
M  +5    -0    tests/qstring-allocations/main.cpp_fixed.cpp.expected

http://commits.kde.org/clazy/7ace8c7a9f4e53efbce017fd95d33797b426bace