code inspection clang-diagnostic-writable-strings not working propertly

for this code:

const char* test(const char* param)

{

    char* a = "test";              // get warning, correct.

    const char* b = "test";    // get warning, which should not

    const char* c = (const char*)"test";   // no warning

    return "test";   // get warning, which should not

}

test("param");    // get warning, which should not

test((const char*)"param"); // no warning

 

so according to this, is this by design?

 

 

0
9 comments
Avatar
Permanently deleted user

Hello,

Sorry, I can't reproduce this - clang-tidy only shows me one clang-diagnostic-writable-strings warning on this code and it's correct.

Which R++ version are you using? Could you please create a request in https://youtrack.jetbrains.com and attach a sample solution with this issue?

Thanks!

0
Avatar
Permanently deleted user

Sorry, I forgot to say, this will only reproduce in Visual Studio Linux Project.

I'm using Visual Studio Professional 2017 Version 15.7.3 and Resharper C++ 2018.1

0
Avatar
Permanently deleted user

Still can't reproduce even with a Linux project. It seems like const was defined to be empty - if you invoke "Go to declaration" on const, does anything happen?

0
Avatar
Permanently deleted user

"Go to declaration" on const is grey, which is disabled. so here const is a c++ keyword I think.

0
Avatar
Permanently deleted user

At least clang thinks that const is missing for some reason. Could you please send us this solution, I'll recheck with it.

Where does <cstdio> resolve to for you? On my VS project it goes to "Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\Linux\include\usr\include\c++\5\cstdio".

0
Avatar
Permanently deleted user

Also does it happen if you remove the include directives from your example?

0
Avatar
Permanently deleted user

Yes, when I remove the include directives, the problem is gone.

I'm using VS's Remote Headers IntelliSense Cache, when I delete the cache, [clang-diagnostic-writable-strings] warning is gone too.

So I think this is the problem.

When I remove the cache by deleteing the cache folder,  <cstdio> will be resolved to "Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\Linux\include\usr\include\c++\5\cstdio" (not just disable the cache in vs options, it will cause <cstdio> can not be resolved)

here is my cache detail:

C:\Users\Raven\AppData\Local\Microsoft\Linux\Header Cache\1.0\977886017\home\raven\bin\..\lib\gcc\x86_64-pc-linux-gnu\7.1.0\..\..\..\..\include\c++\7.1.0

C:\Users\Raven\AppData\Local\Microsoft\Linux\Header Cache\1.0\977886017\home\raven\bin\..\lib\gcc\x86_64-pc-linux-gnu\7.1.0\..\..\..\..\include\c++\7.1.0\x84_64-pc-linux-gnu

C:\Users\Raven\AppData\Local\Microsoft\Linux\Header Cache\1.0\977886017\home\raven\bin\..\lib\gcc\x86_64-pc-linux-gnu\7.1.0\..\..\..\..\include\c++\7.1.0\backward

C:\Users\Raven\AppData\Local\Microsoft\Linux\Header Cache\1.0\977886017\home\raven\bin\..\lib\gcc\x86_64-pc-linux-gnu\7.1.0\..\..\..\..\include\c++\7.1.0\include

C:\Users\Raven\AppData\Local\Microsoft\Linux\Header Cache\1.0\977886017\home\raven\bin\..\lib\gcc\x86_64-pc-linux-gnu\7.1.0\..\..\..\..\include\c++\7.1.0\include-fixed

C:\Users\Raven\AppData\Local\Microsoft\Linux\Header Cache\1.0\977886017\usr\local\include

C:\Users\Raven\AppData\Local\Microsoft\Linux\Header Cache\1.0\977886017\home\raven\bin\..\lib\gcc\..\..\include

C:\Users\Raven\AppData\Local\Microsoft\Linux\Header Cache\1.0\977886017\usr\include

 

 

 

0
Avatar
Permanently deleted user

Could you please archive the cached headers and attach them to https://youtrack.jetbrains.com/issue/RSCPP-23186? We'll try to create a minimal repro.

Thanks!

0
Avatar
Permanently deleted user

Ok, I have uploaded an attachment.

0

Please sign in to leave a comment.