Error for identifying C++11's range-based for loos in Mac

33 views
Skip to first unread message

Victoria Ponce

unread,
Apr 5, 2016, 1:25:56 PM4/5/16
to deal.II User Group
Hello,

I'm working in a deal code that uses C++11's range-based for loops and it runs perfectly in linux. Now, I'm trying to run this code in a Mac and I'm getting the following error: 

/Users/victoria/workspace_mac/moving_boundary_model/moving_boundary_code/source/localequation_homogenized.cc:115:1: error: 'auto' deduced as

      'dealii::TriaActiveIterator<dealii::DoFCellAccessor<dealii::hp::DoFHandler<2, 2>, false> >' in declaration of 'cell' and deduced as

      'dealii::TriaIterator<dealii::DoFCellAccessor<dealii::hp::DoFHandler<2, 2>, false> >' in declaration of 'endc'

auto cell = pi.dof_handler.begin_active(), 


I've tried to find out why I'm getting this error but I've had no luck... I wanted to know if this error has to do with the fact that my clang version doesn't support C++11's range-based for loops? or could be related to the way I installed deal ? 

At this moment, I'm using deal developer version and Apple LLVM version 7.0.0 (clang-700.1.76) which I think should support auto loops.

Any comments or suggestions would be highly appreciated.

Thanks!

Wolfgang Bangerth

unread,
Apr 5, 2016, 1:49:03 PM4/5/16
to dea...@googlegroups.com
On 04/05/2016 12:25 PM, Victoria Ponce wrote:
>
> I'm working in a deal code that uses C++11's range-based for loops and
> it runs perfectly in linux. Now, I'm trying to run this code in a Mac
> and I'm getting the following error:
>
> */Users/victoria/workspace_mac/moving_boundary_model/moving_boundary_code/source/localequation_homogenized.cc:115:1:
> **error: **'auto' deduced as*
>
> *'dealii::TriaActiveIterator<dealii::DoFCellAccessor<dealii::hp::DoFHandler<2,
> 2>, false> >' in declaration of 'cell' and deduced as*
>
> *'dealii::TriaIterator<dealii::DoFCellAccessor<dealii::hp::DoFHandler<2,
> 2>, false> >' in declaration of 'endc'*
>
> auto cell = pi.dof_handler.begin_active(),
>
>
> I've tried to find out why I'm getting this error but I've had no
> luck... I wanted to know if this error has to do with the fact that my
> clang version doesn't support C++11's range-based for loops? or could be
> related to the way I installed deal ?
>
> At this moment, I'm using deal developer version and Apple LLVM version
> 7.0.0 (clang-700.1.76) which I think should support auto loops.
>
> Any comments or suggestions would be highly appreciated.

The problem is that you wrote something like
auto cell = dh.begin_active(),
endc = dh.end();

Here, the two right hand sides have different types (the first is an
*active* cell iterator, the latter just a regular cell iterator; but
they can be converted into each other). Your compiler then doesn't know
which type you want for the 'auto' (which should be the same type for
both variables).

You should be able to solve this by declaring the two variables separately:
auto cell = dh.begin_active();
auto endc = dh.end();

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@math.tamu.edu
www: http://www.math.tamu.edu/~bangerth/

Victoria Ponce

unread,
Apr 6, 2016, 6:27:03 AM4/6/16
to deal.II User Group


Thanks. I did the change that you proposed and the code runs. 


I'm just a bit curious of why the error is not spotted when I'm running the code in linux? is it maybe because I'm using a different compiler and it is deducing the type of iterator as I wanted to? Is it always the case that if I used auto for endc it will assume the type of iterator as the previous one or how does it know which type of iterator to assume?

Thanks for the help.

Best,
Victoria Ponce.

Wolfgang Bangerth

unread,
Apr 6, 2016, 7:21:37 AM4/6/16
to dea...@googlegroups.com
On 04/06/2016 05:27 AM, Victoria Ponce wrote:
>
> I'm just a bit curious of why the error is not spotted when I'm running the
> code in linux? is it maybe because I'm using a different compiler and it is
> deducing the type of iterator as I wanted to? Is it always the case that if I
> used auto for endc it will assume the type of iterator as the previous one or
> how does it know which type of iterator to assume?
>

Good question. The compiler that accepted the code at first may have a bug.
Reply all
Reply to author
Forward
0 new messages