diff mbox

[testsuite] Fix false FAIL in gdb.cp/casts.exp

Message ID 20160911141027.GA10024@host1.jankratochvil.net
State New
Headers show

Commit Message

Jan Kratochvil Sept. 11, 2016, 2:10 p.m. UTC
Hi,

gcc-6.2.1-1.fc26.x86_64

gdb compile failed, /home/jkratoch/redhat/gdb-clean/gdb/testsuite/gdb.cp/casts.cc:40:10: error: expected primary-expression before 'int'
 decltype(int x)
          ^~~
/home/jkratoch/redhat/gdb-clean/gdb/testsuite/gdb.cp/casts.cc:40:10: error: expected ')' before 'int'
/home/jkratoch/redhat/gdb-clean/gdb/testsuite/gdb.cp/casts.cc:40:1: error: expected unqualified-id before 'decltype'
 decltype(int x)
 ^~~~~~~~
/home/jkratoch/redhat/gdb-clean/gdb/testsuite/gdb.cp/casts.cc: In function 'int main(int, char**)':
/home/jkratoch/redhat/gdb-clean/gdb/testsuite/gdb.cp/casts.cc:59:14: error: expected primary-expression before 'decltype'
   double y = decltype(2);
              ^~~~~~~~

'decltype' is a registered keyword since C++11 which is now a default for GCC.

OK for check-in?


Jan
gdb/testsuite/ChangeLog
2016-09-11  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.cp/casts.cc: Rename decltype to int_to_double.
	* gdb.cp/casts.exp (whatis decltype(5)): Rename to ...
	(whatis int_to_double(5)): ... here.

Comments

Pedro Alves Sept. 15, 2016, 12:06 p.m. UTC | #1
On 09/11/2016 03:10 PM, Jan Kratochvil wrote:
> --- a/gdb/testsuite/gdb.cp/casts.exp
> +++ b/gdb/testsuite/gdb.cp/casts.exp
> @@ -112,7 +112,7 @@ gdb_test "print reinterpret_cast<A &> (*b)" " = \\(A \\&\\) @$hex: {a = 42}" \
>  
>  # Test that keyword shadowing works.
>  

This comment suggests that the test actually uses decltype on purpose.

> -gdb_test "whatis decltype(5)" " = double"
> +gdb_test "whatis int_to_double(5)" " = double"
>  

Seems to be exercising the FLAG_SHADOW bits:

...
    {"__typeof__", TYPEOF, OP_TYPEOF, 0 },
    {"__typeof", TYPEOF, OP_TYPEOF, 0 },
    {"typeof", TYPEOF, OP_TYPEOF, FLAG_SHADOW },
    {"__decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX },
    {"decltype", DECLTYPE, OP_DECLTYPE, FLAG_CXX | FLAG_SHADOW },
...

/* This is used to associate some attributes with a token.  */

enum token_flag
{
...
  /* If this bit is set, the token is conditional: if there is a
     symbol of the same name, then the token is a symbol; otherwise,
     the token is a keyword.  */

  FLAG_SHADOW = 2
};

So perhaps a better fix is to move that particular test to a
separate testcase that force-compiles with -std=c++03.

Adding Tromey, who wrote the test initially.

Thanks,
Pedro Alves
Tom Tromey Sept. 15, 2016, 1:25 p.m. UTC | #2
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> So perhaps a better fix is to move that particular test to a
Pedro> separate testcase that force-compiles with -std=c++03.

Pedro> Adding Tromey, who wrote the test initially.

Yeah, I think that's correct.  According to the patch email, I did this
because there wasn't a way to tell which version of C++ was in use:

https://sourceware.org/ml/gdb-patches/2012-07/msg00349.html

Tom
diff mbox

Patch

diff --git a/gdb/testsuite/gdb.cp/casts.cc b/gdb/testsuite/gdb.cp/casts.cc
index 43f112f..4f68ba0 100644
--- a/gdb/testsuite/gdb.cp/casts.cc
+++ b/gdb/testsuite/gdb.cp/casts.cc
@@ -37,7 +37,7 @@  struct DoublyDerived : public VirtuallyDerived,
 // Confuse a simpler approach.
 
 double
-decltype(int x)
+int_to_double(int x)
 {
   return x + 2.0;
 }
@@ -56,7 +56,7 @@  main (int argc, char **argv)
   Alpha *ad = &derived;
   Alpha *add = &doublyderived;
 
-  double y = decltype(2);
+  double y = int_to_double(2);
 
   return 0;  /* breakpoint spot: casts.exp: 1 */
 }
diff --git a/gdb/testsuite/gdb.cp/casts.exp b/gdb/testsuite/gdb.cp/casts.exp
index 34a2492..5798098 100644
--- a/gdb/testsuite/gdb.cp/casts.exp
+++ b/gdb/testsuite/gdb.cp/casts.exp
@@ -112,7 +112,7 @@  gdb_test "print reinterpret_cast<A &> (*b)" " = \\(A \\&\\) @$hex: {a = 42}" \
 
 # Test that keyword shadowing works.
 
-gdb_test "whatis decltype(5)" " = double"
+gdb_test "whatis int_to_double(5)" " = double"
 
 # Basic tests using typeof.