0

For the code bellow:

auto main() -> int {
  char arr[] = {'a', 'b', 'c'};
  char * p = arr;
  char ** pp = &p;
  const char * const * p_const = pp;
}

Clion says that there is an error on the last line const char * const * p_const = pp;

"Assigning 'char * *' to 'const char * const *' discards const qualifier"

AFAIK, this cast is allowed and the code compiles.

Is there a way to fix the problem?

Andrey Tonkih
  • 331
  • 2
  • 8
  • 1
    No repro with gcc7.1 and clang4.0. Probably broken Apple-LLVM again, no idea why people keep using that... – Baum mit Augen Jul 10 '17 at 16:48
  • 4
    Take a look at one of these [C++ books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Ron Jul 10 '17 at 16:48
  • Btw I had to ask about that `auto main() -> int {}` sorcery and was told [this so post](https://stackoverflow.com/questions/22514855/arrow-operator-in-function-heading/22515589#22515589) has the answer. – Ron Jul 10 '17 at 17:03
  • @Ron Sorcery? That's just modern C++ trailing return type. Some 6 years old by now.. – Jesper Juhl Jul 10 '17 at 17:12
  • 4
    @JesperJuhl When used to represent a simple `int main()` it looks more like unnecessary obfuscation (sorcery) to me. – Ron Jul 10 '17 at 17:14
  • "CLion finds false error" - well, compilers are not fail safe you know. There are always going to be false positives with their error messages once in a while. – Jesper Juhl Jul 10 '17 at 17:23
  • Do you get this error on compiling or in the editor as an analysis? – Ilya Popov Jul 10 '17 at 22:55
  • @IlyaPopov as an analysis. The code compiles well. – Andrey Tonkih Jul 11 '17 at 11:03

0 Answers0