Skip to content

AST parser error 'for (const std::string &i : v)' #511

@Bertk

Description

@Bertk

The following code creates parser errors (line 11 and line 23).

// Win32Project1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
  std::vector<std::string> v = { "test1", "test2", "test3" };

  for (const std::string &i : v) // access by const reference
    std::cout << i.c_str() << ' ';
  std::cout << '\n';

  for (auto i : v) // access by value, the type of i is int
    std::cout << i.c_str() << ' ';
  std::cout << '\n';

  for (auto&& i : v) // access by reference, the type of i is int&
    std::cout << i.c_str() << ' ';
  std::cout << '\n';

  for (std::string n : {"test1", "test2", "test3"}) // the initializer may be a braced-init-list
    std::cout << n.c_str() << ' ';
  std::cout << '\n';

    return 0;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions