Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A7-1-1: false positive on non-const variables in class templates #18

Closed
Assignees
mbaluda
Labels
Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-Mediumfalse positive/false negativeAn issue related to observed false positives or false negatives.user-reportIssue reported by an end user of CodeQL Coding Standards
@mbaluda

Description

@mbaluda

Affected rules

  • A7-1-1

Description

In the following code the member variablet_ is modified by the non-const member functionInit. If the class is not a template no error is reported for similar code.

Example

template<typename T>classA7_1_1bfinal {public:explicitA7_1_1b(std::int64_t i)noexcept { t_.Init(i); }// t_ is modified here by Initprivate:  T t_;// <= A7-1-1: Non-constant variable t_ is used for an object and is not modified.};

Example

#include<iostream>#include<vector>namespacetest {/// doctemplate<classT>classMyClassfinal {private:// CodeQL reports: A7-1-1:cpp/autosar/declaration-unmodified-object-missing-const-specifier// Non-constant variable data_ is used for an object and is not modified.// Marking this as "const" is incorrect, we can modify the data through the iterator returned// by the begin() function, adding const here does not compile.  std::vector<T> data_;};}// namespace test/// mainintmain(int,char**)noexcept {try {    test::MyClass<int>c({1,2,3});  }catch (const std::exception&) {  }}

Metadata

Metadata

Assignees

Labels

Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-Mediumfalse positive/false negativeAn issue related to observed false positives or false negatives.user-reportIssue reported by an end user of CodeQL Coding Standards

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp