[GRASS-dev] [GRASS GIS] #1765: variable length array error in r.terraflow with clang

#1765: variable length array error in r.terraflow with clang
-----------------------+----------------------------------------------------
Reporter: kyngchaos | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Keywords: clang | Platform: MacOSX
      Cpu: OSX/Intel |
-----------------------+----------------------------------------------------
Another clang compiler issue in r.terraflow:

{{{
/Users/Shared/src/GRASS/svn/dev6-r53518/dist.x86_64-apple-
darwin11.4.2/include/grass/iostream/empq_impl.h:1360:41: error:
       variable length array of non-POD element type
       'ExtendedEltMergeType<keyvalue<cclabel_type>, int>'
   ExtendedEltMergeType<T,Key> in_objects[arity];
}}}

A bit of searching tells me that non-POD variable length arrays are not
part of the C++ spec, but supported as an extension in some compilers.
clang does not.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
-----------------------+----------------------------------------------------
Reporter: kyngchaos | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Keywords: clang | Platform: MacOSX
      Cpu: OSX/Intel |
-----------------------+----------------------------------------------------

Comment(by glynn):

Replying to [ticket:1765 kyngchaos]:
> A bit of searching tells me that non-POD variable length arrays are not
part of the C++ spec, but supported as an extension in some compilers.
clang does not.

I suggest using std::vector instead; see attachment:empq.patch

PS: the "using namespace std" should be eliminated. It's a bad idea in
source files, but far worse in headers.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
-----------------------+----------------------------------------------------
Reporter: kyngchaos | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Keywords: clang | Platform: MacOSX
      Cpu: OSX/Intel |
-----------------------+----------------------------------------------------

Comment(by vince):

+ 1.
clang-3.2 seems to be build the rest of Grass fine.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
-----------------------+----------------------------------------------------
Reporter: kyngchaos | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Keywords: clang | Platform: MacOSX
      Cpu: OSX/Intel |
-----------------------+----------------------------------------------------

Comment(by glynn):

Replying to [comment:1 glynn]:

> I suggest using std::vector instead; see attachment:empq.patch

Applied in r54320.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
-----------------------+----------------------------------------------------
Reporter: kyngchaos | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Keywords: clang | Platform: MacOSX
      Cpu: OSX/Intel |
-----------------------+----------------------------------------------------

Comment(by neteler):

Replying to [comment:3 glynn]:
> Applied in r54320.

Backport to GRASS 6?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
-----------------------+----------------------------------------------------
Reporter: kyngchaos | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Keywords: clang | Platform: MacOSX
      Cpu: OSX/Intel |
-----------------------+----------------------------------------------------

Comment(by glynn):

Replying to [comment:4 neteler]:
> Backport to GRASS 6?
Yes.

The 6.5 and 7.0 versions are identical except for this fix and the header
comment.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
------------------------+---------------------------------------------------
  Reporter: kyngchaos | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Resolution: fixed | Keywords: clang
  Platform: MacOSX | Cpu: OSX/Intel
------------------------+---------------------------------------------------
Changes (by neteler):

  * status: new => closed
  * resolution: => fixed

Comment:

Also backported to 6.4 and 6.5. Closing.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
------------------------+---------------------------------------------------
  Reporter: kyngchaos | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Resolution: fixed | Keywords: clang
  Platform: MacOSX | Cpu: OSX/Intel
------------------------+---------------------------------------------------

Comment(by glynn):

Replying to [comment:6 neteler]:
> Also backported to 6.4 and 6.5. Closing.
FWIW, I fixed a couple of other portability issues in r54330. Two more
VLAs, string literals are "const char *", and "%lf" isn't a valid printf()
specifier.
Issues which weren't fixed include:
  * Extraneous commas at the end of enum definitions and extraneous
semicolons after function definitions (these are trivial, and would add a
lot of noise to the diff)
  * Use of "long long" and "%lld", for which there's no easy fix.
Add -ansi and -pedantic to CXXFLAGS for the details.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
------------------------+---------------------------------------------------
  Reporter: kyngchaos | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Resolution: fixed | Keywords: clang
  Platform: MacOSX | Cpu: OSX/Intel
------------------------+---------------------------------------------------

Comment(by neteler):

Replying to [comment:7 glynn]:
> FWIW, I fixed a couple of other portability issues in r54330.

Backported in r54330, r54335 and r54336.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:8&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
------------------------+---------------------------------------------------
  Reporter: kyngchaos | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Resolution: fixed | Keywords: clang
  Platform: MacOSX | Cpu: OSX/Intel
------------------------+---------------------------------------------------

Comment(by neteler):

Unfortunately the backport is incompliant with r.terraflow in G6:
{{{[neteler@north r.terraflow]$ make
c++ -c -I/home/neteler/grass64/dist.x86_64-unknown-linux-gnu/include -g
-Wall -DUSER=\"neteler\" -DNODATA_FIX -D_FILE_OFFSET_BITS=64
-DPACKAGE=\""grassmods"\" -DELEV_FLOAT main.cc -o OBJ.x86_64-unknown-
linux-gnu/FLOAT/main.o
In file included from /home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq.h:33:0,
                  from /home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:41,
                  from /home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami.h:39,
                  from common.h:27,
                  from main.cc:39:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h: In member function ‘AMI_err
em_buffer<T, Key>::substream_merge(AMI_STREAM<T>**, unsigned int,
AMI_STREAM<T>*)’:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h:989:3: error: ‘vector’ is not a
member of ‘std’
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h:989:16: error: expected primary-
expression before ‘*’ token
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h:989:17: error: expected primary-
expression before ‘>’ token
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h:989:35: error: there are no
arguments to ‘in_objects’ that depend on a template parameter, so a
declaration of ‘in_objects’ must be available [-fpermissive]
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h:989:35: note: (if you use
‘-fpermissive’, G++ will accept your code, but allowing the use of an
undeclared name is deprecated)
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h:1018:46: error: ‘in_objects’ was not
declared in this scope
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h:1048:43: error: ‘in_objects’ was not
declared in this scope
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h:1053:46: error: ‘in_objects’ was not
declared in this scope
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/embuffer.h:1063:15: error: ‘in_objects’ was not
declared in this scope
In file included from /home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami.h:39:0,
                  from common.h:27,
                  from main.cc:39:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h: In member function ‘AMI_err
em_pqueue<T, Key>::merge_buffer(em_buffer<T, Key>*,
AMI_STREAM<ExtendedEltMergeType<T, Key> >*, long int)’:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1250:3: error: ‘vector’ is not a
member of ‘std’
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1250:16: error: expected primary-
expression before ‘*’ token
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1250:17: error: expected primary-
expression before ‘>’ token
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1250:35: error: there are no
arguments to ‘in_objects’ that depend on a template parameter, so a
declaration of ‘in_objects’ must be available [-fpermissive]
In file included from /home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami.h:39:0,
                  from common.h:27,
                  from main.cc:39:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1278:41: error: ‘in_objects’ was
not declared in this scope
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1313:37: error: ‘in_objects’ was
not declared in this scope
In file included from /home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami.h:39:0,
                  from common.h:27,
                  from main.cc:39:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h: In member function ‘AMI_err
em_pqueue<T, Key>::merge_streams(AMI_STREAM<ExtendedEltMergeType<T, Key>
>**, short unsigned int, AMI_STREAM<ExtendedEltMergeType<T, Key> >*, long
int)’:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1375:3: error: ‘vector’ is not a
member of ‘std’
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1375:43: error: expected primary-
expression before ‘>’ token
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1375:61: error: there are no
arguments to ‘in_objects’ that depend on a template parameter, so a
declaration of ‘in_objects’ must be available [-fpermissive]
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1399:4: error: ‘in_objects’ was not
declared in this scope
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_impl.h:1427:36: error: ‘in_objects’ was
not declared in this scope
In file included from /home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_adaptive_impl.h:30:0,
                  from /home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami.h:41,
                  from common.h:27,
                  from main.cc:39:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_adaptive.h: In constructor
‘EMPQueueAdaptive<T, Key>::EMPQueueAdaptive(long int)’:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/empq_adaptive.h:53:47: warning: delegating
constructors only available with -std=c++11 or -std=gnu++11 [enabled by
default]
main.cc: In function ‘void printMaxSortSize(long int)’:
main.cc:436:43: warning: format ‘%d’ expects argument of type ‘int’, but
argument 4 has type ‘long unsigned int’ [-Wformat]
main.cc:439:83: warning: format ‘%d’ expects argument of type ‘int’, but
argument 4 has type ‘long unsigned int’ [-Wformat]
main.cc: In function ‘int main(int, char**)’:
main.cc:622:16: warning: zero-length gnu_printf format string [-Wformat-
zero-length]
In file included from main.cc:43:0:
grass2str.h: In instantiation of ‘AMI_STREAM<T>* cell2stream(char*,
elevation_type, long int*) [with T = float; elevation_type = float]’:
main.cc:558:25: required from here
grass2str.h:144:3: warning: format ‘%lld’ expects argument of type ‘long
long int’, but argument 5 has type ‘off_t {aka long int}’ [-Wformat]
In file included from /home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami.h:27:0,
                  from common.h:27,
                  from main.cc:39:
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h: In instantiation of ‘AMI_err
AMI_STREAM<T>::write_item(const T&) [with T = float]’:
grass2str.h:128:4: required from ‘AMI_STREAM<T>* cell2stream(char*,
elevation_type, long int*) [with T = float; elevation_type = float]’
main.cc:558:25: required from here
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h:583:3: warning: comparison between
signed and unsigned integer expressions [-Wsign-compare]
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h: In instantiation of ‘AMI_err
AMI_STREAM<T>::read_item(T**) [with T = short int]’:
grass2str.h:193:4: required from ‘void stream2_CELL(AMI_STREAM<T>*,
dimension_type, dimension_type, char*, bool) [with T = short int;
dimension_type = short int]’
main.cc:575:51: required from here
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h:521:3: warning: comparison between
signed and unsigned integer expressions [-Wsign-compare]
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h: In instantiation of ‘AMI_err
AMI_STREAM<T>::read_item(T**) [with T = float]’:
grass2str.h:193:4: required from ‘void stream2_CELL(AMI_STREAM<T>*,
dimension_type, dimension_type, char*, bool) [with T = float;
dimension_type = short int]’
main.cc:580:62: required from here
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h:521:3: warning: comparison between
signed and unsigned integer expressions [-Wsign-compare]
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h: In instantiation of ‘AMI_err
AMI_STREAM<T>::read_item(T**) [with T = labelElevType]’:
grass2str.h:274:3: required from ‘void stream2_CELL(AMI_STREAM<T>*,
dimension_type, dimension_type, FUN, char*) [with T = labelElevType; FUN =
labelElevTypePrintLabel; dimension_type = short int]’
main.cc:585:26: required from here
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h:521:3: warning: comparison between
signed and unsigned integer expressions [-Wsign-compare]
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h: In instantiation of ‘AMI_err
AMI_STREAM<T>::read_item(T**) [with T = sweepOutput]’:
grass2str.h:448:3: required from ‘void stream2_FCELL(AMI_STREAM<T>*,
dimension_type, dimension_type, FUN1, FUN2, char*, char*) [with T =
sweepOutput; FUN1 = printAccumulation; FUN2 = printTci; dimension_type =
short int]’
main.cc:609:36: required from here
/home/neteler/grass64/dist.x86_64-unknown-linux-
gnu/include/grass/iostream/ami_stream.h:521:3: warning: comparison between
signed and unsigned integer expressions [-Wsign-compare]
make: *** [OBJ.x86_64-unknown-linux-gnu/FLOAT/main.o] Error 1
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:9&gt;
GRASS GIS <http://grass.osgeo.org>

#1765: variable length array error in r.terraflow with clang
------------------------+---------------------------------------------------
  Reporter: kyngchaos | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 6.4.3
Component: Compiling | Version: svn-develbranch6
Resolution: fixed | Keywords: clang
  Platform: MacOSX | Cpu: OSX/Intel
------------------------+---------------------------------------------------

Comment(by martinl):

Replying to [comment:9 neteler]:
> Unfortunately the backport is incompliant with r.terraflow in G6:

should be fixed in r54337 (g64). Martin

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1765#comment:10&gt;
GRASS GIS <http://grass.osgeo.org>