cpp:S1121 false-positive with Boost.Parameter named arguments

  • What language is this for?
    C++

  • Which rule?
    cpp:S1121Assignments should not be made from within expressions

  • Why do you believe it’s a false-positive/false-negative?
    The rule reports a violation for Boost.Parameter’s named-argument syntax, for example:

    setUp(_value = 1);
    

    Here, if _setUp" is a BOOST_PARAMETER_MEMBER_FUNCTION, _value = 1 is not an assignment whose side effect is being embedded in another expression.
    It is the intended syntax of the Boost.Parameter library for passing a named argument. Boost.Parameter uses the assignment operator syntactically to associate a keyword with its value.

    The expression _value = 1 constructs/passes the named parameter; it does not modify a variable called _value. This is also the documented Boost.Parameter calling convention. For example, the Boost documentation uses calls such as:

    complicated(_b = 'B', _a = 1);
    

    So extracting the “assignment” from the expression is not a meaningful refactoring in this case. For example, this:

    _value = 1;
    setUp();
    

    would be a completely different operation.

    Likewise, introducing a temporary:

    const auto value = 1;
    setUp(_value = value);
    

    only works around the static-analysis rule and makes the code less clear.

  • SonarQube Server
    Enterprise Edition
    v2026.4.1 (126914)

  • Minimal reproducible example:

    #include <boost/parameter.hpp>
    
    BOOST_PARAMETER_NAME(value)
    
    BOOST_PARAMETER_FUNCTION(
        (void),
        foo,
        tag,
        (optional
            (value, (int), 0)
        )
    )
    {
    }
    
    int main()
    {
        foo(_value = 42);
    }
    
    

    cpp:S1121 reports the _value = 42 expression.

  • Relation to existing issue
    This appears to be related to the existing discussion:

    cpp:S1121 false-positive with assignment explicitly enclosed in parentheses

    However, I believe the Boost.Parameter case is a separate issue.

    The existing report concerns an actual C++ assignment:

    foo((a = 1));
    

    where the question is whether S1121 should consider the assignment acceptable because it is explicitly enclosed in parentheses.

    In the Boost.Parameter case, the expression:

    foo(_value = 42);
    

    only looks like an assignment. It is the documented syntax of a third-party C++ library for constructing a named argument.

  • Expected behaviour
    S1121 should ideally recognize Boost.Parameter named-argument expressions as a legitimate C++ idiom and not report them.

    If supporting specific libraries is not appropriate for the rule, it would be helpful to have a recommended way of excluding this pattern from S1121 without disabling the rule more broadly.

  • Environment

    • SonarQube Server Enterprise Edition v2026.4.1 (126914)
    • Boost version: ~1.86.0