Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Compilation error when no required arg in template class

Open
#102 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
compilers

Research direction

Use the reproducer in the issue with boost/parameter.hpp as the starting point, and compile it with both clang++ and g++ to confirm the reported diagnostics. Trace the BOOST_PARAMETER_MEMBER_FUNCTION expansion for the template class when the only parameter is optional. Done means the example compiles and both somebody::f() and somebody::f(4) work across the affected compilers.

Written by the indexing model from the issue text.

Description

Hi boost developers.
I have some compilation trouble when I want to use a BOOST_PARAMETER_MEMBER_FUNCTION with no required argument in a template class. There is no issue for non template class or if I add one require arg.
This code can reproduce my issue (tested with several version of boost 1.65,1.69,1.70,1.71,1.72)

#include <iostream>
#include <boost/parameter.hpp>

BOOST_PARAMETER_NAME(arg1)

template <typename T>
struct somebody
{
  BOOST_PARAMETER_MEMBER_FUNCTION(
                                  (void), static f, tag, (optional (arg1,(int),0))
                                  )
  {
    std::cout << arg1 << std::endl;
  }
};

#include <boost/core/lightweight_test.hpp>

int main()
{
  somebody<double>::f();
  somebody<double>::f(4);
  return boost::report_errors();
}

The error obtained with clang++ :

error: template argument for template type parameter must be a type; did you forget 'typename'?

The error obtained with g++ :

In file included from /usr/include/boost/parameter.hpp:18,
                 from test_boostparameter.cpp:2:
test_boostparameter.cpp:9:3: error: type/value mismatch at argument 1 in template parameter list for 'template<class T> template<class Args> struct somebody<T>::boost_param_result_11f'
   BOOST_PARAMETER_MEMBER_FUNCTION(
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_boostparameter.cpp:9:3: note:   expected a type, got 'boost::parameter::aux::argument_pack<somebody<T>::boost_param_params_11f<int> >::type'
test_boostparameter.cpp:9:3: error: expected ';' at end of member declaration
   BOOST_PARAMETER_MEMBER_FUNCTION(
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_boostparameter.cpp: In function 'int main()':
test_boostparameter.cpp:21:23: error: cannot call member function 'int somebody<T>::f() [with T = double]' without object
   somebody<double>::f();
Dominant language
C++
Stars
16
Forks
42
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/parameter

All issues in boostorg/parameter

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.