This is an archive of the discontinued LLVM Phabricator instance.

[ARM] const cast fix for ARMAttributeParser test
ClosedPublic

Authored by samparker on Feb 1 2017, 1:42 AM.

Details

Reviewers
rengolin
mkuper
Summary

GCC 4.8 produced a cast qualifier warning.

Diff Detail

Event Timeline

samparker created this revision.Feb 1 2017, 1:42 AM
rengolin added inline comments.Feb 1 2017, 2:03 AM
unittests/Support/ARMAttributeParser.cpp
34–35

Weird, the template type is not const...

then, shouldn't this be:

ArrayRef<const uint8_t> Bytes((const uint8_t*)OS.str().c_str(), OS.str().size());

or why can't it just be const char?

It helps reading the warning message :)

../unittests/Support/ARMAttributeParser.cpp: In function ‘bool testBuildAttr(unsigned int, unsigned int, unsigned int, unsigned int)’:
../unittests/Support/ARMAttributeParser.cpp:34:52: warning: cast from type ‘const char*’ to type ‘uint8_t* {aka unsigned char*}’ casts away qualifiers [-Wcast-qual]
   ArrayRef<uint8_t> Bytes((uint8_t*)OS.str().c_str(), OS.str().size());

The AttributeParser::Parse was defined as accepting an ArrayRef<uint8_t> so I just stuck to this. Also, the template type does not need to be const since ArrayRef always uses the type to create a const pointer from it.

rovka added a subscriber: rovka.Feb 1 2017, 3:03 AM

Maybe I'm being a bit pedantic here, but while we're at it, could we also switch to a C++ cast instead of the C-style cast?

The AttributeParser::Parse was defined as accepting an ArrayRef<uint8_t> so I just stuck to this. Also, the template type does not need to be const since ArrayRef always uses the type to create a const pointer from it.

Good point.

samparker updated this revision to Diff 86613.Feb 1 2017, 3:55 AM

Using reinterpret cast for c++ style, including the const qualifier.

rovka accepted this revision.Feb 1 2017, 4:00 AM

LGTM

This revision is now accepted and ready to land.Feb 1 2017, 4:00 AM
rovka edited reviewers, added: mkuper; removed: rovka.Feb 1 2017, 4:37 AM
This revision now requires review to proceed.Feb 1 2017, 4:37 AM

ah, I didn't see your last message and I've already committed! I will manually close this once it is accepted.

rengolin accepted this revision.Feb 1 2017, 6:08 AM

That's ok, this can be a post-commit review.

This revision is now accepted and ready to land.Feb 1 2017, 6:08 AM
samparker closed this revision.Feb 1 2017, 6:13 AM

Closed with commit rL293764