t_5_030.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*=============================================================================
  2. Boost.Wave: A Standard compliant C++ preprocessor library
  3. http://www.boost.org/
  4. Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
  5. Software License, Version 1.0. (See accompanying file
  6. LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. The tests included in this file were initially taken from the mcpp V2.5
  8. preprocessor validation suite and were modified to fit into the Boost.Wave
  9. unit test requirements.
  10. The original files of the mcpp preprocessor are distributed under the
  11. license reproduced at the end of this file.
  12. =============================================================================*/
  13. // Tests whether rescanning of a macro replace any macro call in the replacement
  14. // text after substitution of parameters by pre-expanded-arguments. This
  15. // re-examination may involve the succeeding sequences from the source
  16. // file (what a queer thing!).
  17. // Note: The tests 27.4 and 27.5 are currently disabled because of Wave's
  18. // problem with replacement-list terminating in partial macro expansion.
  19. // 27.1: Cascaded use of object-like macros.
  20. //R #line 34 "t_5_030.cpp"
  21. #define NEST8 NEST7 + 8
  22. #define NEST7 NEST6 + 7
  23. #define NEST6 NEST5 + 6
  24. #define NEST5 NEST4 + 5
  25. #define NEST4 NEST3 + 4
  26. #define NEST3 NEST2 + 3
  27. #define NEST2 NEST1 + 2
  28. #define NEST1 1
  29. NEST8 //R 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
  30. // 27.2: Cascaded use of function-like macros.
  31. //R #line 42 "t_5_030.cpp"
  32. #define FUNC4(a, b) FUNC3(a, b) + NEST4
  33. #define FUNC3(a, b) FUNC2(a, b) + NEST3
  34. #define FUNC2(a, b) FUNC1(a, b) + NEST2
  35. #define FUNC1(a, b) (a) + (b)
  36. FUNC4(NEST1, NEST2) //R (1) + ( 1 + 2) + 1 + 2 + 1 + 2 + 3 + 1 + 2 + 3 + 4
  37. // 27.3: An identifier generated by ## operator is subject to expansion.
  38. //R #line 48 "t_5_030.cpp"
  39. #define GLUE( a, b) a ## b
  40. #define MACRO_1 1
  41. GLUE(MACRO_, 1) //R 1
  42. // 27.4: 'SUB' as an argument of math() is not pre-expanded, since '('
  43. // missing.
  44. //R #line 55 "t_5_030.cpp"
  45. #define SUB(x, y) (x - y)
  46. #define MATH(op, a, b) op( (a), (b))
  47. MATH(SUB, a, b) //R ( ( a) - ( b))
  48. // 27.5: Queer thing.
  49. // R #line 28 "t_5_030.cpp"
  50. //#define HEAD SUB(
  51. // HEAD a,b ) // R
  52. // 27.6: Recursive macro.
  53. //R #line 66 "t_5_030.cpp"
  54. #define M N
  55. #define N(a) a
  56. M(m) //R m
  57. /*-
  58. * Copyright (c) 1998, 2002-2005 Kiyoshi Matsui <kmatsui@t3.rim.or.jp>
  59. * All rights reserved.
  60. *
  61. * Redistribution and use in source and binary forms, with or without
  62. * modification, are permitted provided that the following conditions
  63. * are met:
  64. * 1. Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. * 2. Redistributions in binary form must reproduce the above copyright
  67. * notice, this list of conditions and the following disclaimer in the
  68. * documentation and/or other materials provided with the distribution.
  69. *
  70. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
  71. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  72. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  73. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
  74. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  75. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  76. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  77. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  78. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  80. * SUCH DAMAGE.
  81. */