Skip to content

Commit bd74d87

Browse files
authored
Merge pull request #2343 from tautschnig/c++-auto
C++11 auto type specifier
2 parents 278e506 + af83568 commit bd74d87

16 files changed

+124
-8
lines changed

regression/cpp/auto1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.cpp
33
-std=c++11
44
^EXIT=0$

regression/cpp/auto2/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
int main()
2+
{
3+
#ifndef _MSC_VER
4+
// Visual Studio uses C++14 by default, thus the below would not be valid
5+
auto int x = 42;
6+
#endif
7+
}

regression/cpp/auto2/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.cpp
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

regression/cpp/auto3/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
int main()
2+
{
3+
#ifndef _MSC_VER
4+
// should yield a parse error unless in C++11 (or later) mode
5+
auto x = 42;
6+
const auto y = 42;
7+
const auto &z = y;
8+
#else
9+
intentionally invalid
10+
#endif
11+
}

regression/cpp/auto3/test.desc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.cpp
3+
4+
^EXIT=(64|1)$
5+
^SIGNAL=0$
6+
parse error
7+
--
8+
^warning: ignoring
9+
^CONVERSION ERROR$

regression/cpp/auto4/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int main()
2+
{
3+
auto x = 42;
4+
const auto y = 42;
5+
const auto &z = y;
6+
}

regression/cpp/auto4/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.cpp
3+
-std=c++11
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/cpp/cpp_convert_type.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,19 @@ void cpp_convert_plain_type(typet &type)
591591
cpp_convert_type.write(type);
592592
}
593593
}
594+
595+
void cpp_convert_auto(typet &dest, const typet &src)
596+
{
597+
if(dest.id() != ID_merged_type && dest.has_subtype())
598+
{
599+
cpp_convert_auto(dest.subtype(), src);
600+
return;
601+
}
602+
603+
cpp_convert_typet cpp_convert_type(dest);
604+
for(auto &t : cpp_convert_type.other)
605+
if(t.id() == ID_auto)
606+
t = src;
607+
608+
cpp_convert_type.write(dest);
609+
}

src/cpp/cpp_convert_type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1616

1717
void cpp_convert_plain_type(typet &);
1818

19+
void cpp_convert_auto(typet &dest, const typet &src);
20+
1921
#endif // CPROVER_CPP_CPP_CONVERT_TYPE_H

src/cpp/cpp_declarator_converter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ symbolt &cpp_declarator_convertert::convert(
6868
scope=&cpp_typecheck.cpp_scopes.current_scope();
6969

7070
// check the declarator-part of the type, in that scope
71-
cpp_typecheck.typecheck_type(final_type);
71+
if(declarator.value().is_nil() || !cpp_typecheck.has_auto(final_type))
72+
cpp_typecheck.typecheck_type(final_type);
7273
}
7374

7475
is_code=is_code_type(final_type);

0 commit comments

Comments
 (0)