<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - AUTOSAR rules for range loops"
   href="https://bugs.llvm.org/show_bug.cgi?id=45711">45711</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>AUTOSAR rules for range loops
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>michael.krasnyk@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello,


i am working on a project that uses clang and an AUTOSAR compliance tool.
I would like to file not a bug but an issue that two AUTOSAR rules are
counter-exclusive for code generated by llvm.

Namely,

Rule A6-5-1 (required, implementation, automated)
A for-loop that loops through all elements of the container and does not use
its loop-counter shall not be used.

The rules implies that following code has to be used

#include <vector>

void f(std::vector<int> values)
{
    for (auto value : values)
    {

    }
}

The clang generates the following code

#include <vector>

void f(std::vector<int, std::allocator<int> > values)
{
  {
    std::vector<int, std::allocator<int> > & __range1 = values;
    __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int> >
<span class="quote">> __begin1 = __range1.begin();</span >
    __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int> >
<span class="quote">> __end1 = __range1.end();</span >
    for(; __gnu_cxx::operator!=(__begin1, __end1); __begin1.operator++())
    {
      int value = __begin1.operator*();
    }

  }
}

and the AUTOSAR compliance tool shows violations of another rule

Rule A8-5-2 (required, implementation, automated)
Braced-initialization {}, without equals sign, shall be used for variable
initialization

as AUTOSAR C++14 Declarators (AUTOSAR C++14 A8-5-2)1.
autosar_cpp14_a8_5_2_violation: Initializing variable __range1 without using
braced-initialization {}.

Would it be beneficial for llvm to change implementation of initialization of
__range, __begin, __end in range-based loops in Sema::ActOnCXXForRangeStmt from

T & ref = object ;

to

T & ref { object } ;

so the code above will be

      std::vector<int, std::allocator<int> > & __range1{values};
      __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int>
<span class="quote">> > __begin1{__range1.begin()};</span >
      __gnu_cxx::__normal_iterator<int *, std::vector<int, std::allocator<int>
<span class="quote">> > __end1{__range1.end()};</span >


Regards,
Michael Krasnyk</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>