Skip to content

Added cfg information about std::span#4762

Merged
orbitcowboy merged 6 commits intocppcheck-opensource:mainfrom
Ashimaru:spancfg
Feb 5, 2023
Merged

Added cfg information about std::span#4762
orbitcowboy merged 6 commits intocppcheck-opensource:mainfrom
Ashimaru:spancfg

Conversation

@Ashimaru
Copy link
Copy Markdown
Contributor

@Ashimaru Ashimaru commented Feb 1, 2023

Basic information about std::span type, I was not sure how to approach its std::dynamic_extent so I omitted it

@chrchr-github
Copy link
Copy Markdown
Collaborator

Thanks for contributing. Can you add a test case to show that it works? std.cpp should be the right location.

@chrchr-github
Copy link
Copy Markdown
Collaborator

Since std::span is C++20, you need to update the language standard, see edb0b63

With this change, will we warn for the code below?

int f() {
    std::span<int> s;
    {
        std::vector<int> v(1);
        s = v;
    }
    return s.back();
}

@Ashimaru
Copy link
Copy Markdown
Contributor Author

Ashimaru commented Feb 2, 2023

Yeah, I already found it but thanks :) As for the snippet i will add it - I admit I missed that now I should provide such tests but I will add then in this PR

@Ashimaru Ashimaru marked this pull request as draft February 2, 2023 15:45
@Ashimaru
Copy link
Copy Markdown
Contributor Author

Ashimaru commented Feb 2, 2023

I added tests for back/front/last/first operations and I started copying string_view tests since span sues similar process. During tests I also found that int example std::vector v{1} do not generate same issues, I suspect its caused that cfg defines that stdVector starts with std::vector< where as of c++17 '<' is optional.
Should I raise it in forum for adding ticket or just create another PR with needed tests and fix?

@Ashimaru Ashimaru marked this pull request as ready for review February 2, 2023 21:24
@Ashimaru
Copy link
Copy Markdown
Contributor Author

Ashimaru commented Feb 3, 2023

Seems like c++20 flag is not supported for Ubuntu 20.04 (too old g++), should I change it to 2a or is there different way you guys are handing those issues?

@chrchr-github
Copy link
Copy Markdown
Collaborator

You could try if the 2a flag is sufficient for std::span. The standard was only recently raised to C++17.
Regarding the std::vector v{1} issue, you're welcome to open another PR. I'm not sure though if it can be solved with configuration alone.

@Ashimaru
Copy link
Copy Markdown
Contributor Author

Ashimaru commented Feb 5, 2023

Could you aprprove test run here?

@chrchr-github
Copy link
Copy Markdown
Collaborator

Maybe @firewave can do that.

@orbitcowboy orbitcowboy merged commit 7ae7ad6 into cppcheck-opensource:main Feb 5, 2023
@Ashimaru Ashimaru deleted the spancfg branch February 6, 2023 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants