[go: up one dir, main page]

Menu

#276 Redundant "const" breaks build with clang

OBSOLETE_(1.18.x)
closed-fixed
None
Compilation
1
2016-04-23
2014-12-05
Mikhail T.
No

Building pidgin-sipe on FreeBSD-10.1, where clang-3.4.1 is the default compiler, I had to fix the following problem:

sipe-ews-autodiscover.c:313:42: error: duplicate 'const' declaration specifier [-Werror,-Wduplicate-decl-specifier]
        static const struct autodiscover_method const methods[] = {
                                                ^
1 error generated.

That said, I find it commendable, that pidgin-sipe project aims to deliver warning-free code. Thank you!

Related

Release Notes: 2014/12/pidgin-sipe-release-1185

Discussion

  • Stefan Becker

    Stefan Becker - 2014-12-05
    • status: open --> closed-wont-fix
     
  • Stefan Becker

    Stefan Becker - 2014-12-05

    It's a const array of const structures. I don't see anything wrong with that code.

    Closing as WONTFIX.

     
  • Mikhail T.

    Mikhail T. - 2014-12-05

    I think, the difference is in using the array notation ([]) rather than pointer (*). With array, the second const is redundant, because the entire contents of the array is already const.

     
  • Marek

    Marek - 2014-12-08

    In C++ either both the array and its elements are const or neither are const. (See 8.3.4p1 [dcl.array] of the C++11 standard) Therefore the compiler is correctly warning that the const is redundant as per the specification.

    Note that 7.1.6.1p1 [dcl.type.cv] says that redunant cv-qualifiers are ignored, but this provision is for types created by typedef and simmilar.

    Some searching revealed that GCC might have some sort of feature which allows you to have non-const elements in a const array (which seems like a terrible idea as an array in that form is really just the memory taken by its elements).

    The true problem is including -Werror by default in your code release. Warnings change not only between compilers but also between compiler versions. This means that such a release is only guaranteed to build with the exact compiler and version it was developed with even though there are no real issues with the code.

     
  • Marek

    Marek - 2014-12-08

    I got a little carried away there since this project isn't actually written in C++, but the part about array declaration did not change from the C standard.

     
  • Stefan Becker

    Stefan Becker - 2014-12-09

    If you don't like -Werror then I would suggest studying the output of ./configure --help:

    ...
      --enable-quality-check  compile with compiler checks enabled [default=yes]
    ...
    
     
  • Mikhail T.

    Mikhail T. - 2014-12-09

    I for one like -Werror -- because it helps identify the bugs like this one. The bugs need fixing upon being identified, however...

     
  • Marek

    Marek - 2014-12-09

    I got a hold of the C11 standard and in 6.7.3p9 states: "If the specification of an array type includes any type qualifiers, the element type is so-qualified, not the array type." So the second const is redundant. 6.7.3p5 says redundant qualifiers are ignored.

    -Werror is known to break things with clang. The effort to build all debian packages with clang ( http://clang.debian.net/ ) lists packages that break just because they enable -Werror by default. I imagine that this would be true for any compiler that isn't compatible with the compiler a project is developed with.

    If you'd like to see all the warnings clang can give you, try building with -Weverything ( http://clang.llvm.org/docs/UsersManual.html#diagnostics-enable-everything ).

     
  • Stefan Becker

    Stefan Becker - 2014-12-10

    Why are you wasting time on this useless discussion?

    -Werror will never be removed, because it was added for a reason. If clang can't handle this, then use --disable-quality-check.

    Furthermore: I'll pretend that clang does not exist until such a time that a platform that uses it goes online on OBS. So if you want to spend time on something useful work toward adding your favorite *BSD platform on OBS.

     
  • Marek

    Marek - 2014-12-10

    Now I remember why I love open source.

     
  • Stefan Becker

    Stefan Becker - 2014-12-11

    Looks like GCC no longer generates different code with or without const, i.e. both arrays are in ROM and not copied to RAM. Tested with

    :::sh
    $ gcc --version
    gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7)
    $ gcc -v
    ...
    Target: x86_64-redhat-linux
    
    $ gcc -o dummy.s -S dummy.c
    
     
  • Stefan Becker

    Stefan Becker - 2014-12-11

    Fixed by git commit e7a448f9

    But my statement for clang still holds true: as long as no platform on OBS uses it, SIPE compilation errors from clang will be considered as zero priority.

     
  • Stefan Becker

    Stefan Becker - 2014-12-11
    • summary: Redundant "const" breaks build with a picky compiler --> Redundant "const" breaks build with clang
    • status: closed-wont-fix --> closed-fixed
    • assigned_to: Stefan Becker
    • Priority: 5 --> 1
     
  • Marek

    Marek - 2014-12-11

    Thank you for taking your time fixing this bug and for your patience.

     

Log in to post a comment.